I'm building a new Excel workbook in c# by combining the first sheet of a series of different Excel workbooks; subsequently I export the new Workbook to PDF. I made this work, but there is always one Excel instance running by the end of the method. I had the same issue discussed here with a simpler setup and less Excel objects that I could solve with the GC.Collect command. Now, none of
我在c#中构建了一个新的Excel工作簿,将一系列不同的Excel工作簿中的第一张合并在一起; 随后我将新的工作簿导出为PDF。 我做了这项工作,但总是有一个Excel实例在该方法结束时运行。 我在这里讨论了与使用GC.Collect命令可以解决的更简单的设置和更少的Excel对象相同的问题。 现在,这些都不起作用。 public void CombineWorkBooks() { Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Off
I am working with Excel Interop COM object. I am writing a method in which I am opening and closing an Excel application followed by opening an Excel workbook and sheet. After I'm done working on them I am closing both the application and workbook. My problem is that this method can be called repeatedly several times and when the sheet and app are closing I get from the Excel application a
我正在使用Excel Interop COM对象。 我正在编写一个方法,在该方法中打开和关闭Excel应用程序,然后打开Excel工作簿和工作表。 在完成它们之后,我正在关闭应用程序和工作簿。 我的问题是,这种方法可以重复调用几次,当表格和应用程序关闭时,如果我想保存所做的更改,我会从Excel应用程序中获取一条消息。 该方法卡住,直到我按“否”,但我不能告诉用户每次按下它。 如何关闭应用程序而不收到此消息或至少通过代码回答它
I am trying to properly close the excel COM object such as excel application workbook and worksheet. I have browsed all the solution on this site and other site. Nothing works. Only way is to run a loop to kill or excel process. is there a better way or a way to kill only single excel file process? #region VARIABLE int nColumn = 0; int nIMPORT = 1;
我想正确关闭excel COM对象,如Excel应用程序工作簿和工作表。 我浏览了本网站和其他网站上的所有解决方案。 什么都没有 唯一的方法是运行一个循环来杀死或优化进程。 有没有更好的方法或只杀死单个Excel文件过程的方法? #region VARIABLE int nColumn = 0; int nIMPORT = 1; int endofsheet = 0; string IMPORTfilepath = null; string nsheet = n
I'm working on a C# project that uses Microsoft.Office.Interop.Excel.Application to read values from an Excel file: try { Application xlApp = new Application(); Workbook workbook = xlApp.Workbooks.Open(filename) // ... Load Excel values ... } finally { // ... Tidy up ... } In the finally block I'd like to make sure everything is closed and disposed of properly so nothing
我正在研究使用Microsoft.Office.Interop.Excel.Application从Excel文件读取值的C#项目: try { Application xlApp = new Application(); Workbook workbook = xlApp.Workbooks.Open(filename) // ... Load Excel values ... } finally { // ... Tidy up ... } 在finally块中,我想确保所有内容都被关闭并妥善处理,所以没有任何东西在内存中挂起,并且Excel完全关闭。 已经看到了这个代码应该看起来像什么
I have successfully converted a Excel file to a pdf file using the code below. I tried to release the excel object using the following method. - Quit & Close & null - Never use two-dots with COM objects - ReleaseComObject - GC.Collect But, still remains "EXCEL.EXE" at Task Manager. I do not want to terminate "EXCEL.EXE" by calling process list in the task
我已经成功地使用下面的代码将Excel文件转换为PDF文件。 我试图用下面的方法释放excel对象。 - 退出并关闭&null - 切勿对COM对象使用双点 - ReleaseComObject - GC.Collect 但是,在任务管理器中仍然保留“EXCEL.EXE”。 我不想通过调用任务管理器中的进程列表来终止“EXCEL.EXE” 我该如何解决这个问题? public bool ExportWorkbookToPdf(string workbookPath, string outputPath) { // If either requ
We are using excel interop to create excel reports in a windows service. Everything works fine in Windows 7 OS. But when the service is deployed in Win2K8R2 server, observed that following exception is thrown while saving the excel document using "SaveAs()" method. Exception - HRESULT: 0x800A03EC After researching got to know that, we need to use "SaveCopyAs()" or use &q
我们正在使用excel interop在windows服务中创建excel报告。 一切工作正常在Windows 7操作系统。 但是,当服务部署在Win2K8R2服务器上时,观察到使用“SaveAs()”方法保存Excel文档时抛出以下异常。 异常 - HRESULT:0x800A03EC 经过研究后才知道,我们需要使用“SaveCopyAs()”或使用“Close()”而不是SaveAs()方法。 我尝试使用“SaveCopyAs()”方法,发现excel报告创建工作正常,但任务管理器中的“Excel.exe”仍然存
We use Excel interop in numerous places in our code, however I have one function which doesn't ever seem to close down the Excel process it uses.. I've simplified the code down, and it just seems like whenever I open a workbook in this function it stays hanging around. I've included the code below, I've made sure every object is defined, released and nulled, and yet Excel stays r
我们在代码中的很多地方使用Excel interop,但是我有一个函数似乎并没有关闭它使用的Excel进程..我已经简化了代码,它只是看起来像每当我打开一个工作簿在这个功能中它一直处于悬挂状态。 我已经包含了下面的代码,我确保每个对象都被定义,发布和清零,但Excel仍在运行。 System.Data.DataTable dtExcelSheet = new System.Data.DataTable(); Microsoft.Office.Interop.Excel.Application excelObject = new M
All of these questions: Excel 2007 Hangs When Closing via .NET How to properly clean up Excel interop objects in C# How to properly clean up interop objects in C# struggle with the problem that C# does not release the Excel COM objects properly after using them. There are mainly two directions of working around this issue: Kill the Excel process when Excel is not used anymore. Take c
所有这些问题: 通过.NET关闭时Excel 2007挂起 如何在C#中正确清理Excel互操作对象 如何正确清理C#中的互操作对象 与使用它们之后C#不能正确释放Excel COM对象的问题斗争。 围绕这个问题主要有两个方向: 当Excel不再使用时,杀掉Excel进程。 注意明确地将每个用于变量的COM对象首先分配给变量,并保证每个变量都执行Marshal.ReleaseComObject。 有些人表示2太繁琐,你是否忘记在代码中的某些地方忘记遵守这条
Consider the following C# code using a COM object. MyComObject o = new MyComObject; try { var baz = o.Foo.Bar.Baz; try { // do something with baz } finally { Marshal.ReleaseComObject(baz); } } finally { Marshal.ReleaseComObject(o); } This will release the COM objects o and baz , but not the temporary objects returnd by o.Foo and o.Foo.Bar . This can cause problems, when those o
考虑使用COM对象的以下C#代码。 MyComObject o = new MyComObject; try { var baz = o.Foo.Bar.Baz; try { // do something with baz } finally { Marshal.ReleaseComObject(baz); } } finally { Marshal.ReleaseComObject(o); } 这将释放COM对象o和baz ,但不会释放由o.Foo和o.Foo.Bar的临时对象。 当这些对象拥有大量非托管内存或其他资源时,这可能会导致问题。 一个明显但很难看的解决方案是,用try-f
Why does this line of code cause Excel not to exit? Excel.Range range = (Excel.Range)ws.Cells[1,1]; If it's because of the casting, then wouldn't this code cause the same problem? Excel.Worksheet ws = (Excel.Worksheet)wb.ActiveSheet; I've tried. But this works. Excel will close. If I use this code. Excel closes. Excel.Range range = ws.get_Range("A1","A1"); So what's the
为什么这行代码导致Excel不能退出? Excel.Range range = (Excel.Range)ws.Cells[1,1]; 如果是因为铸造,那么这个代码是不是会导致同样的问题? Excel.Worksheet ws = (Excel.Worksheet)wb.ActiveSheet; 我试过了。 但是,这工作。 Excel将关闭。 如果我使用这个代码。 Excel关闭。 Excel.Range range = ws.get_Range("A1","A1"); 那有什么区别? 是的,我知道有一百万的“如何正确关闭Excel”线程。 但既然这是一个