I am using this code to read an Excel spreadsheet:
using Excel = Microsoft.Office.Interop.Excel;
namespace myProject
{
public class uploadfile
{
public void ReadFile(string file, string companycode)
{
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
Excel.Range range;
string str;
int rCnt = 0;
int cCnt = 0;
xlApp = new Excel.Application(); //<==Crashes right here
xlWorkBook = xlApp.Workbooks.Open(file, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
//Code eliminated for brevity
}
}
}
I get error 0x80040154, "Class not registered", each time I run this code. I have tried targeting X86 and reinstalled Office on my PC. I have search the internet but in most sources, it is a problem after it is installed on someone's machine, but it is happening to me in VS2010.