我正在尝试打开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参考,但仍有问题,我缺少什么?
答案 0 :(得分: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;
谢谢!