问题
When I save an excel workbook :
xlWorkbook.SaveAs("C:\\output\\excelfile.xls", Excel.XlFileFormat.xlCSV,
misValue, misValue, false, false, Excel.XlSaveAsAccessMode.xlNoChange,
misValue, misValue, misValue, misValue, misValue);
it have no proplem.
But
String str = "C:\\output\\excelfile.xls";// or get file path from saveFileDialog
xlWorkbook.SaveAs(str, Excel.XlFileFormat.xlCSV,
misValue, misValue, false, false, Excel.XlSaveAsAccessMode.xlNoChange,
misValue, misValue, misValue, misValue, misValue);
I found "comexception was unhandled cannot access *.xls", why is that?

回答1:
I just tried it and it works for me:
private void button1_Click(object sender, EventArgs e)
{
var xlApp = ((TaskPaneView)this.Parent).currentInstance;
Workbook xlWorkbook = xlApp.Workbooks[1];
var misValue = Type.Missing;
xlWorkbook.SaveAs("C:\\temp\\excelfile.xls", XlFileFormat.xlCSV,
misValue, misValue, false, false, XlSaveAsAccessMode.xlNoChange,
misValue, misValue, misValue, misValue, misValue);
xlWorkbook.SaveAs("C:\\temp\\excelfile.xls", XlFileFormat.xlCSV,
misValue, misValue, false, false, XlSaveAsAccessMode.xlNoChange,
misValue, misValue, misValue, misValue, misValue);
}
On the second SaveAs I get this prompt:

来源:https://stackoverflow.com/questions/16755659/trouble-in-excel-workbook-saveas