1

我正在尝试打开一个 Excel 文件,刷新它后面的查询,然后在 C# 中保存并关闭该文件。

我有以下内容,但首先出现以下行的错误:

        object _missingValue = System.Reflection.Missing.Value;
        Application excel = new Application();
        Workbook theWorkbook = excelFile.Workbooks._Open(txtLocation.Text, _missingValue, _missingValue, _missingValue, _missingValue, _missingValue, _missingValue, _missingValue, _missingValue, _missingValue, _missingValue, _missingValue, _missingValue);
        Sheets sheets = (Sheets)theWorkbook.Worksheets;
        theWorkbook.RefreshAll();
        theWorkbook.Save();
        excel.Quit();

我添加了 Microsoft.Office.Interop.Excel 参考,但仍然有问题,我缺少什么?

4

1 回答 1

1

通过以下方式解决:

object _missingValue = System.Reflection.Missing.Value;
            Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();
            Workbook theWorkbook = excel.Workbooks.Open(txtLocation.Text, _missingValue, _missingValue, _missingValue, _missingValue, _missingValue, _missingValue, _missingValue, _missingValue, _missingValue, _missingValue, _missingValue, _missingValue);
Sheets sheets = (Sheets)theWorkbook.Worksheets;
theWorkbook.Save();
excel.Quit();
return true;

谢谢!

于 2012-10-03T15:49:13.523 回答