读取数据后在C#中关闭Excel应用程序进程 [英] Closing Excel Application Process in C# after reading datat

查看:550
本文介绍了读取数据后在C#中关闭Excel应用程序进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在使用互操作读取excel文件,但在打开文件并在关闭对话框时读取它。我该怎么办呢

这是我到目前为止所写的

Hi,

I an reading an excel file using the interop , but after opening the file and reading it while closing a dialog box comes. how can i handle it
This is what i have written so far

private void ReadExcel()
        {
            Excel.Application xlApp = new Excel.Application();
            Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(openFileDialog1.FileName);
            Excel._Worksheet xlWorksheet = xlWorkbook.Sheets[1];
            Excel.Range xlRange = xlWorksheet.UsedRange;
            .
            .
            .
            .
            xlWorkbook.Close(0);
            xlApp.Quit();
        }





这会阻止对话框,但TFS会出错。错误是TFS Foundation在执行操作时发现错误,请保存更改并重新启动应用程序



This will prevent the dialog box, but an error comes from TFS . The error is "TFS Foundation found an error while performing operation, please save the changes and restart the application"

推荐答案

看看这里: Workbook.Close方法 [ ^ ]



如你所见关闭方法有3个输入: SaveChanges 文件名 RouteWorkbook 。在您的情况下,最重要的是: SaveChanges 。它应该只有 true false 值,但是......



Have a look here: Workbook.Close method[^]

As you can see Close method has 3 inputs: SaveChanges, Filename, RouteWorkbook. In your case, the most important is: SaveChanges. It should be only true or false values, but...

MSDN写道:

如果工作簿发生更改并且工作簿出现在其他打开的窗口中,则忽略此参数。如果工作簿发生更改但工作簿未出现在任何其他打开的窗口中,则此参数指定是否应保存更改,如下面的列表所示。

If there are changes to the workbook and the workbook appears in other open windows, this argument is ignored. If there are changes to the workbook but the workbook does not appear in any other open windows, this argument specifies whether changes should be saved, as shown in the following list.


这篇关于读取数据后在C#中关闭Excel应用程序进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆