troubleshooting Question

C# application spawning phantom Excel sessions

Avatar of rwheeler23
rwheeler23Flag for United States of America asked on
C#
9 Comments1 Solution19 ViewsLast Modified:
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);
        }
ASKER CERTIFIED SOLUTION
ste5an
Senior Developer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 9 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros