如何关闭excel进程?
我在网上也查了些代码,但是有点问题。程序如下:
//新建个实力,系统中生成一个excel进程
editExcel = new Excel.Application(); //如果在这个地方操作的话,可以结束进程。
System.Runtime.InteropServices.Marshal.ReleaseComObject(editExcel);
editExcel = null;
GC.Collect();失败情况如下:
//新建个实力,系统中生成一个excel进程
editExcel = new Excel.Application();
//下面这段不太理解,也是在网上查的,不些之后的代码会出错
Excel.Workbooks workBooks = editExcel.Application.Workbooks;
workBooks.Open(fileName, missing, missing, missing,
missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing); //再执行上面可用的代码则无效,进程还在
System.Runtime.InteropServices.Marshal.ReleaseComObject(editExcel);
System.Runtime.InteropServices.Marshal.ReleaseComObject(workBooks);
editExcel = null;
workBooks = null;
GC.Collect();
是否和open有关呢?还是open后开了新的文件??请高手帮忙~~~~~~~
我在网上也查了些代码,但是有点问题。程序如下:
//新建个实力,系统中生成一个excel进程
editExcel = new Excel.Application(); //如果在这个地方操作的话,可以结束进程。
System.Runtime.InteropServices.Marshal.ReleaseComObject(editExcel);
editExcel = null;
GC.Collect();失败情况如下:
//新建个实力,系统中生成一个excel进程
editExcel = new Excel.Application();
//下面这段不太理解,也是在网上查的,不些之后的代码会出错
Excel.Workbooks workBooks = editExcel.Application.Workbooks;
workBooks.Open(fileName, missing, missing, missing,
missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing); //再执行上面可用的代码则无效,进程还在
System.Runtime.InteropServices.Marshal.ReleaseComObject(editExcel);
System.Runtime.InteropServices.Marshal.ReleaseComObject(workBooks);
editExcel = null;
workBooks = null;
GC.Collect();
是否和open有关呢?还是open后开了新的文件??请高手帮忙~~~~~~~
我原来在一个项目中用过。也是偶尔会关闭不了。。
引用Interop.Excel.dll Excel.Application appExcel = null;
try
{
appExcel = new Excel.Application();
//你的操作
appExcel.Quit();
return;
}
catch
{
} if (appExcel != null) appExcel.Quit();