紧急求救:在aspx网页中起用服务器段Excel.exe,却无法关闭Excel.exe问题
我在aspx网页中起用服务器段Excel.exe,却无法关闭Excel.exe问题
代码如下:
Microsoft.Office.Interop.Excel.Application oExcel;
Workbook oBook;
Worksheet oSheet;
Range oRange;
Object oMissing = System.Reflection.Missing.Value;
oExcel = new Application();
string strTargerFile=Server.MapPath(".")+"\\Excel\\excelFile.xls";
oBook = oExcel.Workbooks.Add(strTargerFile);
try
{
oBook.Saved = true;
oExcel.UserControl = false;
oExcel.ActiveWorkbook.SaveCopyAs (strTargerFile);
oExcel.Quit();
Response.Redirect (strTargerFile);
}
catch(System.Exception e1)
{
Response.Wirte(e1.Message);
}
finally
{
oExcel.Quit();
}
问题1:
我调用了oExcel的quit方法,本是想结束进程中的excel.exe进程,可是运行程序以后,察看进程中excel.exe还是存在,这样每运行一次,就会在进程中留有一个excel.exe进程,真是要命,该如何解决阿?
问题2:
另外,我如果把oExcel = new Application(); 这条语句放在try语句快中,总会出现“访问被拒绝的异常”,当如果不放在try{}中,程序也能正常运行下去,这是怎么回事啊。