0

当我保存 Excel 工作簿时:

xlWorkbook.SaveAs("C:\\output\\excelfile.xls", Excel.XlFileFormat.xlCSV, 
  misValue, misValue, false, false, Excel.XlSaveAsAccessMode.xlNoChange, 
  misValue, misValue, misValue, misValue, misValue);

它没有问题。

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);

我发现“comexception is unhandled cannot access *.xls”,这是为什么呢?

在此处输入图像描述

4

1 回答 1

0

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:

enter image description here

于 2013-05-26T02:54:25.693 回答