I have the following blocks of code:
Excel.Application xlApp = new Excel.Application();
Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(this.pathToFile);
Excel._Worksheet xlWorksheet = xlWorkbook.Sheets[1];
Excel.Range xlRange = xlWorksheet.UsedRange;
I push the xlRange into an array using:
someArray = (System.Object[,])xlRange.Value2;
Afterwards I try to cleanup with:
Marshal.ReleaseComObject(xlRange);
Marshal.ReleaseComObject(xlWorksheet);
xlWorkbook.Close();
Marshal.ReleaseComObject(xlWorkbook);
xlApp.Quit();
Marshal.ReleaseComObject(xlApp);
However, even with all four of the excel objects being released with Marshal
, the process stays open and prevents the file from being opened again.
Any ideas as to how to properly clean up Interop
excel objects?