locked
Build Excel spreadsheet dynamically at runtime RRS feed

  • Question

  • User658096098 posted

    I've built an asp.net that takes some data input from the user and generates an Excel spreadsheet based on the data entered by the user.

    This works fine under Windows XP (dev environment) but does not work on the live (Server 2008 R2).

    The code is simply dropping out at the create workbook statement. No error message in the logs.

    My code is thus (failure line in bold)

    Imports Microsoft.Office.Interop

    Dim xlApp As Excel.Application
    Dim xlworkbook As Excel.Workbook
    Dim xlworksheet As Excel.Worksheet

    xlApp = CType(CreateObject("Excel.Application"), Excel.Application)

    xlApp.Visible = True

    xlworkbook = xlApp.Workbooks.Add()

    xlworksheet = CType(xlworkbook.Sheets("sheet1"), Excel.Worksheet)

    as I've mentioned this works as designed in dev, but not in prod. Any ideas?

    Tuesday, June 3, 2014 8:45 AM

Answers

  • User-760709272 posted

    Why would it allow the excel object to be created but then fail when doing the workbook element?

    *shrug*  Who knows, but it's not supported by Microsoft so they have never guaranteed this will ever work.  You also have to remember then when running locally the account being used for the code probably had more and better privaledges than the remote server, and also your code was still only being called once, when you're on a remote server and multiple people are using your code, who knows what is going to happen?  My advice would be to ditch the method you're currently using and do something else with Open XML, Aspose etc.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, June 3, 2014 11:57 AM

All replies

  • User-760709272 posted

    You need Excell installed on the server.  Also this way of doing things is not supported by Microsoft and is almost certainly going to fail in some way.  See if you can use the odbc Excel driver to create your excel spreadsheets instead, or maybe use Open XML.

    Tuesday, June 3, 2014 9:02 AM
  • User658096098 posted

    Excel is installed on the server (Office 2007 full install for coverage).

    Why would it allow the excel object to be created but then fail when doing the workbook element?

    Tuesday, June 3, 2014 9:56 AM
  • User-760709272 posted

    Why would it allow the excel object to be created but then fail when doing the workbook element?

    *shrug*  Who knows, but it's not supported by Microsoft so they have never guaranteed this will ever work.  You also have to remember then when running locally the account being used for the code probably had more and better privaledges than the remote server, and also your code was still only being called once, when you're on a remote server and multiple people are using your code, who knows what is going to happen?  My advice would be to ditch the method you're currently using and do something else with Open XML, Aspose etc.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, June 3, 2014 11:57 AM