clsoe issues excel sheet in C#
-
Hi Experts I'm facing issues when i try close the excel file,it's asking me do need save the changes dialog and also still running the excel exe in task manger how i can close th file with put nay dialog and properly cleanup. This my file op opening code Microsoft.Office.Interop.Excel.Workbook workbooks = bodynitsApplicationClass.Workbooks.Open(filename, 0, true, 5, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0); Microsoft.Office.Interop.Excel.Sheets sheets = workbooks.Worksheets; Close Method code: Marshal.ReleaseComObject(worksheetdetail); worksheetdetail = null; bodynitsApplicationClass.Quit(); while (Marshal.ReleaseComObject(bodynitsApplicationClass) != 0) { } bodynitsApplicationClass = null; GC.Collect(); GC.WaitForPendingFinalizers(); Missing anything ?, Please help me
Cheers,Earn and Enjoy RRave MCTS,MCPD http://ravesoft.blogspot.com
-
Hi Experts I'm facing issues when i try close the excel file,it's asking me do need save the changes dialog and also still running the excel exe in task manger how i can close th file with put nay dialog and properly cleanup. This my file op opening code Microsoft.Office.Interop.Excel.Workbook workbooks = bodynitsApplicationClass.Workbooks.Open(filename, 0, true, 5, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0); Microsoft.Office.Interop.Excel.Sheets sheets = workbooks.Worksheets; Close Method code: Marshal.ReleaseComObject(worksheetdetail); worksheetdetail = null; bodynitsApplicationClass.Quit(); while (Marshal.ReleaseComObject(bodynitsApplicationClass) != 0) { } bodynitsApplicationClass = null; GC.Collect(); GC.WaitForPendingFinalizers(); Missing anything ?, Please help me
Cheers,Earn and Enjoy RRave MCTS,MCPD http://ravesoft.blogspot.com
Thank you much , i found and corrected. Here for you. When you call the CloseMethod(your own method) private void close() { if (bodynitsApplicationClass != null) { bodynitsApplicationClass.DisplayAlerts = false; bodynitsApplicationClass.Workbooks.Close(); Marshal.ReleaseComObject(worksheetdetail); worksheetdetail = null; bodynitsApplicationClass.Quit(); Marshal.ReleaseComObject(bodynitsApplicationClass); bodynitsApplicationClass = null; } } everything dispose and close without dialog. thank you once again.
Cheers,Earn and Enjoy RRave MCTS,MCPD http://ravesoft.blogspot.com