Thursday, 5 September 2013

Releasing Excel*32 process after operation complete

Releasing Excel*32 process after operation complete

Trying to figure out why my EXCEL*32 process remains in use until both the
my application AND the excel file are closed. I must be missing something
after creation, it's like the application is holding onto the EXCEL *32
resource after this code. Any suggestions to get it to 'let go' after it's
export operation is completed?
Also, I do not want to close the newly created Excel sheet, I just want to
release the resource being used in relation to my actual .net application.
Application xls = new Application();
xls.SheetsInNewWorkbook = 1;
// Create our new excel application and add our workbooks/worksheets
Workbook Workbook = xls.Workbooks.Add();
Worksheet CrossoverPartsWorksheet = xls.Worksheets[1];
// Create our new excel application and add our workbooks/worksheets
Workbook Workbook = xls.Workbooks.Add();
Worksheet CrossoverPartsWorksheet = xls.Worksheets[1];
/////////////////////////////////////////
// < DO EXCEL EXPORT OPERATIONS HERE > //
/////////////////////////////////////////
// Release our resources.
Marshal.ReleaseComObject(Workbook);
Marshal.ReleaseComObject(CrossoverPartsWorksheet);
Marshal.ReleaseComObject(xls);

No comments:

Post a Comment