C# and Excel Interop issue, Saving the excel file not smooth

LogInIssue picture LogInIssue · Apr 24, 2009 · Viewed 18.6k times · Source

I could Open and Write to the excel file, but when I try to save the file by passing a path to it, the save operation prompts with the Save dialog. I was expecting it to quitely Save the file at the specified path

The code is as below:

excelApp.Save(exportToDirectory);
excelApp.Quit();

where, exportToDirectory is: "C:\files\strings.xlsx".

PS: I have already checked with the excel version and similar issue.

Thanks

Answer

Mitch Wheat picture Mitch Wheat · Apr 24, 2009

You need to use Workbook.SaveAs instead of Application.Save:

Excel.Application app = new Excel.Application();
Excel.Workbook wb = app.Workbooks.Add(missing);
...
wb.SaveAs(@"C:\temp\test.xlsx", missing, missing, missing, missing,
          missing, Excel.XlSaveAsAccessMode.xlExclusive,
          missing, missing, missing, missing, missing);