Avatar of rwheeler23
rwheeler23
Flag for United States of America

asked on 

C# application spawning phantom Excel sessions

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);
        }
C#

Avatar of undefined
Last Comment
ste5an

8/22/2022 - Mon