Hi, just to add to a caveatashish's answer, when you are finished with your spreadsheetâs tasks it is not enough to close the file. You need to release every COM object which was created and quit the application, you can read more about this on
this discussion:
Code:
xlApp.Quit()
Marshal.ReleaseComObject(xlWorkSheet)
Marshal.ReleaseComObject(xlWorkBook)
Marshal.ReleaseComObject(xlApp)
xlApp = Nothing
Also you can try this simpler approach with a help of this
VB.NET library, it has an easy to use API for
reading an excel file in .NET and you will not have to bother with releasing the COM objects from the memory.
Code:
Dim xlWorkBook As ExcelFile = ExcelFile.Load("c:\test1.xlsx")
Dim xlWorkSheet As ExcelWorksheet = xlWorkBook.Worksheets("sheet1")