tags:

views:

77

answers:

4

Hi I am facing a problem.

In my server, there is no office installed. However, I need to access data from excel file.

I used Microsoft.Office.Interop.Excel dll file. I am under the impression that this will work

because the dll location is

C:\Program Files\Microsoft Visual Studio 9.0\Visual Studio Tools for Office\PIA\Office12\Microsoft.Office.Interop.Excel.dll

The same is available in the server machine also. But it does not have office installed there

But when I ran the program I got the exception

System Exception:System.Runtime.InteropServices.COMException (0x80040154): Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80040154.

Googling does not provide much support.

Also, it is very urgent.

Kindly help.

+1  A: 

You're stuffed basically. The interop file simply points to a COM object which is registered by Excel when it is installed.

Since you don't have Excel, its COM registration won't be in the registry so the interop file is effectively pointing at a broken link hence you get the COMException.

You'll need to install Office to make this works as it stands.

Paolo
+1  A: 

The Office PI assemblies simply wrap the Office COM components to provide an interface that can be called from .NET managed code. You still need Office installed, however, you have other options...

If you are working with Office 2007 files, you could try the Open XML SDK 2.0 for Microsoft Office.

Alternatively, if you are working with files form an earlier version of Office there are third party libraries available, e.g. SpreadsheetGear.

Graham Miller
+1  A: 

If you're using Excel & C#, try http://epplus.codeplex.com/

Free library that can read/write spreadsheets, very very easy to use with Excel.

Example of reading in Excel files as demanded by OP:

FileInfo existingFile = new FileInfo(FilePath);
using (ExcelPackage package = new ExcelPackage(existingFile))
{
    // get the first worksheet in the workbook
    ExcelWorksheet worksheet = package.Workbook.Worksheets[1];
    int col = 2; //The item description
    // output the data in column 2
    for (int row = 2; row < 5; row++)
        Console.WriteLine("\tCell({0},{1}).Value={2}", row, col, worksheet.Cells[row, col].Value);

    // output the formula in row 5
    Console.WriteLine("\tCell({0},{1}).Formula={2}", 3, 5, worksheet.Cells[3, 5].Formula);                
    Console.WriteLine("\tCell({0},{1}).FormulaR1C1={2}", 3, 5, worksheet.Cells[3, 5].FormulaR1C1);

} // the using statement automatically calls Dispose() which closes the package.

PS: Asking with please/thanks will likely get more people to help ;)

Meff
an example for reading an excel sheet
eshwar naidu
http://epplus.codeplex.com/SourceControl/changeset/view/59882#885360Look at sample2.cs in the source code repository.
Meff
+1  A: 

Hi,

Depending on your needs, NPOI may do the work (it does not requires office to be installed).

Vagaus