Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Thursday, April 29, 2010 1:55 PM | 1 vote
Hey,
I'm manipulating an Excel (.xls) file trough C#, and I'm using this function the save the file in the end of my program:
excelWS.SaveAs(@path, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing);
But after it the windows prompt asking to the user if he would like to overwrite the existing file (because i'm saving it with the same name as before).
I'd like to know if there's a way to always overwrite the file, without asking to the user.
Regards
All replies (7)
Friday, April 30, 2010 1:06 PM ✅Answered | 9 votes
Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();
excel.DisplayAlerts = false;
excelSheePrint.SaveAs(filename, Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookDefault, Type.Missing, Type.Missing, true, false, XlSaveAsAccessMode.xlNoChange, XlSaveConflictResolution.xlLocalSessionChanges, Type.Missing, Type.Missing);
If (My Answer) Please mark the replies as answer. Thanks; Else Thank you all the same; My Code Blog:http://nauhil.wordpress.com/
Friday, April 30, 2010 1:20 PM ✅Answered | 1 vote
As a work around
you use File.Exist() to check whether is there any file avaible with the same name, then just delete it File.Delete
that is the only way left. i'm adding sample code. {found here http://www.daniweb.com/forums/thread208167.html }
Friday, April 30, 2010 7:30 AM
As a work around
you use File.Exist() to check whether is there any file avaible with the same name, then just delete it File.Delete
Friday, April 30, 2010 2:44 PM
Thank you all!
It worked =)
Saturday, June 18, 2011 5:51 PM
Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application(); excel.DisplayAlerts = false; excelSheePrint.SaveAs(filename, Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookDefault, Type.Missing, Type.Missing, true, false, XlSaveAsAccessMode.xlNoChange, XlSaveConflictResolution.xlLocalSessionChanges, Type.Missing, Type.Missing); If (My Answer) Please mark the replies as answer. Thanks; Else Thank you all the same; My Code Blog:http://nauhil.wordpress.com/
Hi, I'm trying to open a Excel file, make changes, then save this file.
After playing with the arguments for SaveAs(), so the file name is the same as the one opened,
i cannot find a way to really save my changes.
What're the correct arguments pls ?
Monday, September 30, 2013 4:10 PM
You also need to add "excel.DisplayAlerts = true;" after the SaveAs. If you don't, then you can disable prompts which you may need to see.
Thursday, April 16, 2015 9:10 AM
how can you know this is excel file??