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.
Code:
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:
Code:
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?
Thanks,
Adrian.