Excel.Workbook.SaveAs中的麻烦

时间:2013-05-26 02:20:26

标签: c# excel vsto

当我保存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);

我发现“未经处理的感知无法访问* .xls”, 那是为什么?

enter image description here

1 个答案:

答案 0 :(得分:0)

我刚尝试过,它对我有用:

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

}

在第二个SaveAs上我得到了这个提示:

enter image description here