DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Using Excel Online

  1. #1
    Join Date
    Feb 2007

    Using Excel Online

    Hi there,

    I've created a web using visual studio and c#. What i'm trying to do is read in values from an excel file. I'm using the following code with no problem when i'm running it off the server on my laptop ie. my local host.
    Excel.Application excelApp = new Excel.ApplicationClass();
            Excel.Workbook newWorkbook = excelApp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);
            string workbookPath = fuExcel.PostedFile.FileName;
            Excel.Workbook excelWorkbook = excelApp.Workbooks.Open(workbookPath, 0, true, 5, "", "", true, Excel.XlPlatform.xlWindows, "", false, false, 0, true, false, false);
            Excel.Sheets excelSheets = excelWorkbook.Worksheets;
            string currentSheet = "Contacts";
            Excel.Worksheet excelWorksheet = (Excel.Worksheet)excelSheets.get_Item(currentSheet);
            int rows;
            rows = excelWorksheet.UsedRange.Rows.Count;
            Excel.Range excelCell = (Excel.Range)excelWorksheet.get_Range("A1", "CN" + rows);
            object[,] cells = (object[,])excelCell.Value2;
    However once it's hosted i'm getting the following error:

    Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80040154. 
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
    Exception Details: System.Runtime.InteropServices.COMException: Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80040154.
    Source Error: 
    Line 54: {
    Line 55: //sets up an excel class called excelApp
    Line 56: Excel.Application excelApp = new Excel.ApplicationClass();
    Line 57: Excel.Workbook newWorkbook = excelApp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);
    Line 58:
    Is it at all possible to use this code on a hosted server? Could i maybe install excel on my hosted server?



  2. #2
    Join Date
    Dec 2003
    I would recommend using the data access methods of ADO.NET with Jet OLEDB to read the Excel file rather than use automation.

    Microsoft doesn't really support automation of the Offices apps from unattended clients such as web apps, services and windows services, primarily because of the limitation of their threading models and the fact that there is no way to respond to UI prompts.
    Microsoft MVP (Visual Basic)

Similar Threads

  1. Replies: 12
    Last Post: 03-09-2010, 10:51 AM
  2. Replies: 0
    Last Post: 03-09-2006, 09:40 PM
  3. Replies: 8
    Last Post: 01-23-2006, 04:27 PM
  4. ANN: Active XL Report 4.1 - Excel reporting with practically no coding
    By Alexander Frolov [Afalina Co., Ltd.] in forum vb.announcements
    Replies: 0
    Last Post: 06-24-2002, 12:13 PM
  5. ANN: Active XL Report 4.0 - Excel reporting with practically no coding
    By Afalina Co., Ltd. in forum vb.announcements
    Replies: 0
    Last Post: 04-01-2002, 10:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center