after writing something in a cell of an existing excel file, the excel process in the background didn't close. If i comment out the section with worksheet.Cells[1,1]=2 then the excel process will disappear like expected.
Thx in advance for help.
Here is my code:
Excel.Application exelApp = new Excel.Application();
var workbooks = exelApp.Workbooks;
Excel.Workbook workbook = null;
workbook = workbooks.Open(fileName, 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);
var worksheets = workbook.Worksheets;
Excel.Worksheet worksheet = (Excel.Worksheet)worksheets.get_Item("Einzelliste");
//worksheet.Cells[1, 1] = 2;
workbook.Close(true, Type.Missing, Type.Missing);
workbooks.Close();
exelApp.Quit();
ReleaseObject(worksheet);
ReleaseObject(worksheets);
ReleaseObject(workbook);
ReleaseObject(workbooks);
ReleaseObject(exelApp);
worksheet = null;
worksheets = null;
workbook = null;
workbooks = null;
exelApp = null;
private static void ReleaseObject(object theObject)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(theObject);
}
Edit: According to the suggestion from Mark:
var range =worksheet.get_Range("A1");
range.Value = 1; ReleaseObject(range);
In contradiction to some suggestions that this post is a duplucated question: I have to say that it's not because all the objects were released correctly and there is no use of "double dots" in the source code. The suggested calls of Garbage Collector do not solve the problem either.