Joined December 2017
·

VbNetMatrix

Computer Technicien at VbNetMatrix
·
Mont-Laurier
·

Posted to Read Excel File in C# over 1 year ago

nice to share the code... but there is huge mistake in it:

// never use two dots, all COM objects must be referenced and released individually

and yet, you do:

//Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(@"C:\MyFile.xlsx");

while it should be:
Excel.WorkbookS xlWorkbookS = xlApp.Workbooks
Excel.Workbook xlWorkbook = xlWorkbookS.Open(@"C:\MyFile.xlsx");

and later in GC() you should have BOTH
Marshal.ReleaseComObject(xlWorkbook);
Marshal.ReleaseComObject(xlWorkbookS);

Achievements
1 Karma
0 Total ProTip Views