我在处理完Excel数据后需将其关闭,代码如下:
m_WorkBook.Close(true,Missing.Value,Missing.Value);
m_ExcelApp.Workbooks.Close();
m_ExcelApp.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(m_WorkSheet);
System.Runtime.InteropServices.Marshal.ReleaseComObject(m_WorkBook);
System.Runtime.InteropServices.Marshal.ReleaseComObject(m_ExcelApp);
m_WorkBook = null;
m_WorkSheet = null;
m_ExcelApp = null;
GC.Collect();
但为什么这样执行后在进程中仍有EXCEL.exe, 这样导致在下次打开Excel文档的时候有问题...
不知有何解?(我用的是C#, Excel 2000)
m_WorkBook.Close(true,Missing.Value,Missing.Value);
m_ExcelApp.Workbooks.Close();
m_ExcelApp.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(m_WorkSheet);
System.Runtime.InteropServices.Marshal.ReleaseComObject(m_WorkBook);
System.Runtime.InteropServices.Marshal.ReleaseComObject(m_ExcelApp);
m_WorkBook = null;
m_WorkSheet = null;
m_ExcelApp = null;
GC.Collect();
但为什么这样执行后在进程中仍有EXCEL.exe, 这样导致在下次打开Excel文档的时候有问题...
不知有何解?(我用的是C#, Excel 2000)
------------------------方法可行,我以前编的程序就这样做的
m_WorkSheet = null;
m_ExcelApp = null;你把这三句去掉。
你加了这三句,GC.Collect(); 就没有实际工作了。
m_ExcelApp=null;
GC.Collect();
rptBook.Close(false,outFilePath,true);
rptApp.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(rptSheet);
System.Runtime.InteropServices.Marshal.ReleaseComObject(rptBook);
System.Runtime.InteropServices.Marshal.ReleaseComObject(rptApp);
//强制释放无用资源
GC.Collect();