本文介绍了如何从内存中卸载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"
推荐答案
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.
mySheet = Nothing
range = Nothing
xlApp = Nothing
System.Diagnostics.Process.Start("MyExcelFile.xls");
这篇关于如何从内存中卸载Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!