views:

1931

answers:

4

Hi,

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

+6  A: 

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);
Mitch Wheat
would the downvoter please leave a comment. Thanks.
Mitch Wheat
A: 

Well, here's how Microsoft does it:

// Save the Workbook and quit Excel.
m_objBook.SaveAs(m_strSampleFolder + "Book1.xls", m_objOpt, m_objOpt, 
    m_objOpt, m_objOpt, m_objOpt, Excel.XlSaveAsAccessMode.xlNoChange, 
    m_objOpt, m_objOpt, m_objOpt, m_objOpt);
m_objBook.Close(false, m_objOpt, m_objOpt);
m_objExcel.Quit();

See one of their KB articles.

Cory Larson
A: 

Setting the following properties might also help:

excelApp.DisplayAlerts = false;
excelApp.ScreenUpdating = false;
excelApp.Visible = false;
excelApp.UserControl = false;
excelApp.Interactive = false;
Bravax
A: 

ExcelApp.Interactive = false suppresses any dialog box.

excelApp.ActiveWorkbook.SaveAs(exportDirectory)

Vincent Van Den Berghe