I have a C# application that creates and populates an Excel spreadsheet.
1) Create spreadsheet
2) Populate spreadsheet
3) Save spreadsheet
4) Open spreadsheet
The problem I have is after the user closes the spreadsheet there is a phantom spreadsheet session open. Here is how I am saving the spreadsheet. Is there something I need to add here or perhaps in the code that opens the spreadsheet?
public static Boolean SaveExcelSpreadsheet()
{
/* Save the excel file */
Model.xlWorkBook.SaveAs(Model.excelFullOutputFile, Excel.XlFileFormat.xlOpenXMLWorkbook, Model.misValue, Model.misValue, Model.misValue, Model.misValue, Excel.XlSaveAsAccessMode.xlExclusive, Model.misValue, Model.misValue, Model.misValue, Model.misValue, Model.misValue);
Model.xlWorkBook.Close(true, Model.misValue, Model.misValue);
Model.xlApp.UserControl = true;
Model.xlApp.Quit();
Marshal.ReleaseComObject(Model.xlWorkSheetDetail);
Marshal.ReleaseComObject(Model.xlWorkSheetDist);
Marshal.ReleaseComObject(Model.xlWorkBook);
Marshal.ReleaseComObject(Model.xlApp);
MessageBox.Show("Excel file created , you can find the file " + Model.excelFullOutputFile);
return (true);
}
Our community of experts have been thoroughly vetted for their expertise and industry experience.