在本机用WinFom撰写的过程调用我撰写的OpenExcel(如下)的方法后可以马上关闭Excel, 但是这个方法用在Web上用ASP.Net去呼叫, 在Server端却无法将Excel关闭, 这是为什么 ? 到底要用什么方式才能关闭Excel呢?用Kill Process的方式是可以关闭Excel, 但这会将其它正被使用的Excel一并Close, 会影响其它程序的运作, 要怎么样才能只关闭目前所使用的 Excel呢 ?
到底有没有解呢 ?public string OpenExcel(string file,string pwd){
string sheetname="";
Excel.Application excel=null;
Excel.Workbook workBook=null; try{
excel=new Excel.ApplicationClass();
workBook=excel.Workbooks.Open(file,Type.Missing,Type.Missing,Type.Missing,pwd,
Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,
Type.Missing,Type.Missing); sheetname=((Excel.Worksheet)workBook.Sheets[1]).Name; //取得第一个Sheet name
return sheetname;
}catch(Exception er){
throw new System.Exception("开启Excel失败。"+er.Message);
}finally{
if(excel!=null){
if(workBook!=null){
workBook.Close(false,Type.Missing,Type.Missing);
System.Runtime.InteropServices.Marshal.ReleaseComObject(workBook);
workBook=null;
}
excel.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(excel);
excel=null;
System.GC.Collect();
}
}
}我的Server是Win2000 + MS Excel 9.0 Object Library + IIS 5 + .Net Framwork 1.1
到底有没有解呢 ?public string OpenExcel(string file,string pwd){
string sheetname="";
Excel.Application excel=null;
Excel.Workbook workBook=null; try{
excel=new Excel.ApplicationClass();
workBook=excel.Workbooks.Open(file,Type.Missing,Type.Missing,Type.Missing,pwd,
Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,
Type.Missing,Type.Missing); sheetname=((Excel.Worksheet)workBook.Sheets[1]).Name; //取得第一个Sheet name
return sheetname;
}catch(Exception er){
throw new System.Exception("开启Excel失败。"+er.Message);
}finally{
if(excel!=null){
if(workBook!=null){
workBook.Close(false,Type.Missing,Type.Missing);
System.Runtime.InteropServices.Marshal.ReleaseComObject(workBook);
workBook=null;
}
excel.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(excel);
excel=null;
System.GC.Collect();
}
}
}我的Server是Win2000 + MS Excel 9.0 Object Library + IIS 5 + .Net Framwork 1.1
又要如何只Kill 所指定的ProcessID呢 ?