C#,Close Excel whitout the save as dialog
-
In C# using excel.Application to output report.But when error happend, the excel can't close. I must write some coding for close excel.When Close excel,a save as dialog been showed.I want to not save the book,I want to close the excel only.How to do it? Can you give me a sample?
-
In C# using excel.Application to output report.But when error happend, the excel can't close. I must write some coding for close excel.When Close excel,a save as dialog been showed.I want to not save the book,I want to close the excel only.How to do it? Can you give me a sample?
-
In C# using excel.Application to output report.But when error happend, the excel can't close. I must write some coding for close excel.When Close excel,a save as dialog been showed.I want to not save the book,I want to close the excel only.How to do it? Can you give me a sample?
-
In C# using excel.Application to output report.But when error happend, the excel can't close. I must write some coding for close excel.When Close excel,a save as dialog been showed.I want to not save the book,I want to close the excel only.How to do it? Can you give me a sample?
Take a look at application.DisplayAlerts the .saved can be tricky, and there are situations where the excel doc will toggle it without you explicitly setting it. .Displayalerts suppresses ALL warnings from the excel document, but it definetely gets rid of the "do you want to save" issue.
-
Hi, u can do that by setting the variable of Excel.Workbook to true. i.e. if u have an object of Excel.Workbook called WB then just write WB.Saved = true; before closing the application or excel application. Hope that works for u Regards, Pramod
I post the message in message boards, after this I try to use worksheet.saveas method that save to my driver, then close the worksheet. app.Workbooks[1].SaveAs(@"c:\temp.xls", Missing.Value, Missing.Value, Missing.Value,Missing.Value,Missing.Value, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, Missing.Value,Missing.Value, Missing.Value, Missing.Value, Missing.Value); app.Application.Workbooks.Close(); app.Application.Quit(); app.Quit(); System.Runtime.InteropServices.Marshal.ReleaseComObject (app); the work sheet been closed, but the process still in task manager until my application been closed. Why? so ,I more wrote code Process[] procs = Process.GetProcessesByName("EXCEL"); foreach (Process proc in procs) { if (!proc.CloseMainWindow()) { proc.Kill(); } } GC.Collect(); app = null; At last, the excel porcess been disappeared in task manager.