Cannot clear this Exception!

  • Thread starter Thread starter Francesco2017
  • Start date Start date
F

Francesco2017

Guest
Hi,

I am trying to read some data from a .XLS file using the code below. (Got from online)

I have some time online to crack this to no avail.

I made sure that the 'Micros of.Office.Interop.Excel' is installed.

I have limited knowledge, so I am suck. Apparently this issue is very common with Visual Studio.

I have followed advice from other users. I have also tried a different version of VS, but still no luck.

Can you please guide me to the solution of this problem ?

Regards

Francesco C


private void button3_Click(object sender,EventArgs e)
{

string pathOfExcelFile = "C:\\Users\\FC\\Desktop\\cobra.xls";
Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();


excelApp.DisplayAlerts=false; //Don't want Excel to display error messageboxes
Workbook workbook = excelApp.Workbooks.Open(pathOfExcelFile,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing); //This opens the file
Worksheet sheet = workbook.ActiveSheet; //Get the first sheet in the file
Range bColumn = sheet.get_Range("A",null);

List<string> dataItems = new List<string>();

foreach(object o in bColumn)
{
Range row = o as Range;
string s = row.get_Value(null);
dataItems.Add(s);
Console.WriteLine(s);
}

}


1602038.png

Continue reading...
 
Back
Top