杀死Excel 进程的方法 请高手解释代码
我在网上找到了一种杀死Excel 进程的方法,如下:
System.Runtime.InteropServices.Marshal.ReleaseComObject(worksheets);
System.Runtime.InteropServices.Marshal.ReleaseComObject(worksheet);
...
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);
System.Runtime.InteropServices.Marshal.ReleaseComObject(range);
worksheets=null;worksheet=null; ...
excelApp=null;
range=null;
把操作Excel文件用到的对象实例全部释放。
然后资源回收!
GC.Collect();
说要写到finally中,我写了,可是编译时说worksheets 什么的都不存在,我想可能是需要先定义,可是我不知道具体的意思,请高手帮我解释一下具体操作的方法以及代码的意思。