本文介绍了打开Excel文件,刷新查询并保存C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图打开一个Excel文件,刷新它后面的查询,然后在C#中保存并关闭该文件.
I am trying to open an Excel file, refresh the query behind it and then save and close the file in C#.
我有以下内容,但首先在以下几行出现错误:
I have the following but I am getting errors on the following line first up:
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参考,但是仍然存在问题,我缺少了什么?
I have added the Microsoft.Office.Interop.Excel reference, but still have the issue, what I am missing?
推荐答案
解决以下问题:
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;
谢谢!
这篇关于打开Excel文件,刷新查询并保存C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!