Opening Excel file using C#

  • Thread starter Thread starter Soozi-Wong
  • Start date Start date
S

Soozi-Wong

Guest
My Excel class contains:


using Microsoft.Office.Interop.Excel;
using _Excel = Microsoft.Office.Interop.Excel;

namespace ExcelTest
{
class Excel
{

//global reference
string path = "";
_Application excel = new _Excel.Application();
Workbook wb;
Worksheet ws;

//constructors


public Excel(string path, int sheet)
{
this.path = path;
wb = excel.Workbooks.Open(path);
ws = wb.Worksheets[sheet];
}
}


On executing "wb = excel.Workbooks.Open(path);" I get the following error;

System.InvalidCastException: 'Unable to cast COM object of type 'Microsoft.Office.Interop.Excel.ApplicationClass' to interface type 'Microsoft.Office.Interop.Excel._Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{000208D5-0000-0000-C000-000000000046}' failed due to the following error: Interface not registered (Exception from HRESULT: 0x80040155).'


How do I register or rectify it? Do I have to re-install Excel?

Many thanks

Sue

Continue reading...
 
Back
Top