0

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.

Dan J
  • 16,319
  • 7
  • 50
  • 82
Joe Tyman
  • 1,417
  • 5
  • 28
  • 57

1 Answers1

0

I didn't have the correct version of Office. Switched to using CSV instead of xlsx.

Joe Tyman
  • 1,417
  • 5
  • 28
  • 57