戒烟擅长用C#(在使用Excel自动化) [英] quitting excel with C# (while using excel automation)
问题描述
我使用C#来读/写数据到Excel电子表格。
I'm using c# to read/write data to an excel spreadsheet.
我使用这三个语句来打开我的excel文件
I'm using these three statements to open my excel file
Excel.Application excelapp = new Excel.Application();
Excel._Worksheet worksheet = (Excel._Worksheet)workbook.ActiveSheet;
Excel._Worksheet worksheet = (Excel._Worksheet)workbook.ActiveSheet;
和这两条线来关闭/保存的表单。
And these two lines to close/save the sheet.
workbook.Save();
workbook.Close();
我遇到的问题是,Excel进程仍处于活动状态。 (我用任务管理器来检查。)和读/写数据到工作表后,我有一个像EXCEL 20进程的积极。
The problem I'm having is that the EXCEL process is still active. (I used task manager to check.) And after reading/ writing data to the worksheet I have like 20 EXCEL processes active.
如果任何人都可以告诉我结束excelapp PROC权后,我关闭工作簿,将是巨大的技术。
If anyone can show me a technique of ending the excelapp proc right after i close the workbook that would be great.
非常感谢,阿龙。
推荐答案
要获取
excelapp.Quit();
在使用Excel的所有工作。
after all work with Excel.
如果进程仍在运行,试图使用 Marshal.ReleaseComObject的
所有Excel对象,并强制立即垃圾收集:
If processes still running, try to use Marshal.ReleaseComObject
on all Excel objects and force an immediate garbage collection:
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelapp);
excelapp = null;
GC.Collect();
GC.WaitForPendingFinalizers();
请注意,你需要使用 ReleaseComObject的
不仅你的 excelapp </ code>对象,也与每个簿和工作表,你已经使用。
Note, that you need to use ReleaseComObject
not only with your excelapp
object, but also with every workbook and worksheet, that you had used.
这篇关于戒烟擅长用C#(在使用Excel自动化)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!