• <small id='oMKcr'></small><noframes id='oMKcr'>

    1. <legend id='oMKcr'><style id='oMKcr'><dir id='oMKcr'><q id='oMKcr'></q></dir></style></legend>

    2. <tfoot id='oMKcr'></tfoot>
        <bdo id='oMKcr'></bdo><ul id='oMKcr'></ul>
      <i id='oMKcr'><tr id='oMKcr'><dt id='oMKcr'><q id='oMKcr'><span id='oMKcr'><b id='oMKcr'><form id='oMKcr'><ins id='oMKcr'></ins><ul id='oMKcr'></ul><sub id='oMKcr'></sub></form><legend id='oMKcr'></legend><bdo id='oMKcr'><pre id='oMKcr'><center id='oMKcr'></center></pre></bdo></b><th id='oMKcr'></th></span></q></dt></tr></i><div id='oMKcr'><tfoot id='oMKcr'></tfoot><dl id='oMKcr'><fieldset id='oMKcr'></fieldset></dl></div>

        Excel 进程在互操作后保持打开状态;传统方法不起作用

        Excel process remains open after interop; traditional method not working(Excel 进程在互操作后保持打开状态;传统方法不起作用)

      1. <tfoot id='Xsjxx'></tfoot>
          <bdo id='Xsjxx'></bdo><ul id='Xsjxx'></ul>

            <tbody id='Xsjxx'></tbody>
        • <legend id='Xsjxx'><style id='Xsjxx'><dir id='Xsjxx'><q id='Xsjxx'></q></dir></style></legend>

                <small id='Xsjxx'></small><noframes id='Xsjxx'>

                  <i id='Xsjxx'><tr id='Xsjxx'><dt id='Xsjxx'><q id='Xsjxx'><span id='Xsjxx'><b id='Xsjxx'><form id='Xsjxx'><ins id='Xsjxx'></ins><ul id='Xsjxx'></ul><sub id='Xsjxx'></sub></form><legend id='Xsjxx'></legend><bdo id='Xsjxx'><pre id='Xsjxx'><center id='Xsjxx'></center></pre></bdo></b><th id='Xsjxx'></th></span></q></dt></tr></i><div id='Xsjxx'><tfoot id='Xsjxx'></tfoot><dl id='Xsjxx'><fieldset id='Xsjxx'></fieldset></dl></div>
                  本文介绍了Excel 进程在互操作后保持打开状态;传统方法不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在调试的一些代码遇到问题.Excel互操作用于从工作簿中提取一些值;但是,Excel 在程序退出后仍保持打开状态.我已经尝试过传统的解决方案,但它仍然在运行代码的所有机器上保持对 Excel 的引用

                  I'm running into an issue with some code I'm debugging. Excel interop is used to extract some values from a workbook; however, Excel remains open after the program has exited. I've tried the traditional solution, but it still keeps a reference to Excel open on all machines where the code is run

                  private void TestExcel()
                      {
                          Excel.Application excel = new Excel.Application();
                          Excel.Workbooks books = excel.Workbooks;
                          Excel.Workbook book = books.Open("C:\test.xlsm");
                  
                          book.Close();
                          books.Close();
                          excel.Quit();
                  
                          Marshal.ReleaseComObject(book);
                          Marshal.ReleaseComObject(books);
                          Marshal.ReleaseComObject(excel);
                      }
                  

                  即使是这段简单的代码,也可以让进程运行多个文件(xlsm、xlsx、xls).现在我们有一个解决方法可以杀死我们打开的 Excel 进程,但我宁愿让它为我自己的理智工作.

                  Even this simple piece of code keeps the process running with multiple files (xlsm, xlsx, xls). Right now we have a workaround in place to kill the Excel processes we've opened, but I'd much rather get this working for my own sanity.

                  我应该补充一点,我已将其范围缩小到 Workbook 变量.如果我删除对 books.Open() 的调用以及对 book 的所有引用,那么它会成功关闭.

                  I should add that I have it narrowed down to the Workbook variable. If I remove the call to books.Open() and all references to book then it closes successfully.

                  推荐答案

                  这对我来说很成功:

                          xlApp.Quit();
                  
                          //release all memory - stop EXCEL.exe from hanging around.
                          if (xlWorkBook != null) { Marshal.ReleaseComObject(xlWorkBook); } //release each workbook like this
                          if (xlWorkSheet != null) { Marshal.ReleaseComObject(xlWorkSheet); } //release each worksheet like this
                          if (xlApp != null) { Marshal.ReleaseComObject(xlApp); } //release the Excel application
                          xlWorkBook = null; //set each memory reference to null.
                          xlWorkSheet = null;
                          xlApp = null;
                          GC.Collect();
                  

                  这篇关于Excel 进程在互操作后保持打开状态;传统方法不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Performance overhead of using attributes in .NET(在 .NET 中使用属性的性能开销)
                  Accessing attribute info from DTE(从 DTE 访问属性信息)
                  c# Hide a property in datagridview with datasource(c#使用数据源隐藏datagridview中的属性)
                  Extract Display name and description Attribute from within a HTML helper(从 HTML 帮助器中提取显示名称和描述属性)
                  How can I force the PropertyGrid to show a custom dialog for a specific property?(如何强制 PropertyGrid 显示特定属性的自定义对话框?)
                  Associate attribute with code generated property in .net(将属性与 .net 中的代码生成属性相关联)
                    <bdo id='uZwQb'></bdo><ul id='uZwQb'></ul>
                      <tfoot id='uZwQb'></tfoot>

                      • <i id='uZwQb'><tr id='uZwQb'><dt id='uZwQb'><q id='uZwQb'><span id='uZwQb'><b id='uZwQb'><form id='uZwQb'><ins id='uZwQb'></ins><ul id='uZwQb'></ul><sub id='uZwQb'></sub></form><legend id='uZwQb'></legend><bdo id='uZwQb'><pre id='uZwQb'><center id='uZwQb'></center></pre></bdo></b><th id='uZwQb'></th></span></q></dt></tr></i><div id='uZwQb'><tfoot id='uZwQb'></tfoot><dl id='uZwQb'><fieldset id='uZwQb'></fieldset></dl></div>
                              <tbody id='uZwQb'></tbody>
                          1. <small id='uZwQb'></small><noframes id='uZwQb'>

                            <legend id='uZwQb'><style id='uZwQb'><dir id='uZwQb'><q id='uZwQb'></q></dir></style></legend>