如何从内存中卸载Excel [英] How to unload Excel from memory
本文介绍了如何从内存中卸载Excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从C#中打开了excel.但是当我关闭Excel时,它挂在了内存中.
I opened excel from c#. But when i close Excel it''s hangs in the memory.
Worksheet mySheet = workbook.Sheets[WorkSheet];
range = mySheet.get_Range("C3", "C3");
range.Value2 = groupName;
xlApp.Visible = true;
我不需要从C#关闭Excel.我要关闭"Excel中的Excel"
I don''t need close Excel from c#. I want close "Excel from Excel"
推荐答案
您创建的所有Com对象都需要释放,Excel才能关闭.
试试:
All Com objects you created need to be released for Excel to close.
Try:
workbook.Close();
xlApp.Quit();
Marshal.ReleaseComObject(workbook);
Marshal.ReleaseComObject(mySheet);
Marshal.ReleaseComObject(range);
Marshal.ReleaseComObject(xlApp);
GC.Collect();
GC.WaitForPendingFinalizers();
This has worked for me.
毕竟,您需要销毁变量;)
After all, you need to destroy variable ;)
mySheet = Nothing
range = Nothing
xlApp = Nothing
您也可以尝试使用一些第三方[a href ="http://www.gemboxsoftware.com/spreadsheet/overview"> Excel C#不使用 Excel Interop 的库(因此Excel应用不会挂在内存中),然后使用
You can also try to use some 3rd party Excel C# library that doesn''t use Excel Interop (so Excel app won''t hang in memory) and open Excel app from C# with
System.Diagnostics.Process.Start("MyExcelFile.xls");
这篇关于如何从内存中卸载Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文