发布Excel Interop COM对象.. [英] Releasing Excel Interop COM Objects..
本文介绍了发布Excel Interop COM对象..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public void button1_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "Excel File|*.xls|Excel File|*.xlsx";
openFileDialog1.ShowDialog();
string path = openFileDialog1.FileName;
comboBox1.Items.Clear();
Microsoft.Office.Interop.Excel.Application xlr = new
Microsoft.Office.Interop.Excel.Application();
Workbook wb = xlr.Workbooks.Open(path, 0, false, 5, "", "", false,
XlPlatform.xlWindows, "", true, false, 0, true, false, false);
foreach (Worksheet w in xlr.Worksheets)
{
comboBox1.Items.Add(w.Name);
}
xlr.Visible = true;
wb.Close();
xlr.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(wb);
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlr);
}
如何安全地丢弃/发布Excel COM上面代码中的对象??
即使以上述方式发布后,我发现excel正在进程中的任务管理器中运行...?
How can i safely dispose off/Release Excel COM objects in the above code??
Even after releasing in the above fashion i see that excel is running in the task manager under processes ...?
推荐答案
这可能会帮助您 http://stackoverflow.com/questions/158706/how-to-properly-clean-up-excel-interop-objects [ ^ ]
this might help you http://stackoverflow.com/questions/158706/how-to-properly-clean-up-excel-interop-objects[^]
这篇关于发布Excel Interop COM对象..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文