打开Excel文件,刷新查询和保存C#(Open Excel File, Refresh Query

2019-10-17 07:20发布

我试图打开一个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引用,但仍然有问题,我很想念?

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

谢谢!



文章来源: Open Excel File, Refresh Query and Save C#
标签: c# excel-2010