62,074
社区成员
发帖
与我相关
我的任务
分享
finally
{
((MicroExcel._Application)tempApp).Workbooks.Close();
Int32 tempGeneration = GC.GetGeneration(tempApp);
((MicroExcel._Application)tempApp).Quit();
GC.Collect(tempGeneration);
//上面部分在Winform中就已经干掉EXCEL进程了,但是在asp.net中还不行
Process[] myProcesses;
myProcesses = Process.GetProcessesByName("Excel");
//得不到Excel进程ID,暂时只能判断进程启动时间
foreach (Process myProcess in myProcesses)
{
try
{
DateTime startTime = myProcess.StartTime;
if (startTime >= tempStart && startTime <= tempEnd)
{
myProcess.Kill();
}
}//直接在VS中运行网页就不会有取不到StartTime的问题
catch//有一些核心进程是不允许访问的,因此而引起的异常可以捕获并放弃处理
{ }
}
}
程序开始时执行次
GC.Collect();
ApplicationClass excel;
_Workbook xBk;
_Worksheet xSt;
excel = new ApplicationClass();
xBk = excel.Workbooks.Add(true);
xSt = (_Worksheet)xBk.ActiveSheet;
//自定义代码...
//结束时
xBk.Close(false, null, null);
excel.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(xBk);
System.Runtime.InteropServices.Marshal.ReleaseComObject(excel);
System.Runtime.InteropServices.Marshal.ReleaseComObject(xSt);
xBk = null;
excel = null;
xSt = null;
GC.Collect();
怎么可能,我做了半年多excel报表操作,从没有杀不掉的excel进程
/**自定义代码结束**/
string sTimes = DateTime.Now.ToString("yyyyMMddHHmmss");
string strFileName = "";
System.IO.FileInfo file;
strFileName = Server.MapPath("Uploads/qafiles/") + sTimes + ".xls";
xBk.SaveCopyAs(strFileName);
xBk.Close(false, null, null);
excel.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(xBk);
System.Runtime.InteropServices.Marshal.ReleaseComObject(excel);
System.Runtime.InteropServices.Marshal.ReleaseComObject(xSt);
xBk = null;
excel = null;
xSt = null;
//听说你是***中最好的一种,可为什么如此善良的你,却无情的闯了进来
GC.Collect();
file = new System.IO.FileInfo(strFileName);
Response.Clear();
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(file.Name));
Response.AddHeader("Content-Length", file.Length.ToString());
Response.ContentType = "application/ms-excel";
Response.WriteFile(file.FullName);
Response.End();
接上在加上GC.Collect();
程序开始时执行次
GC.Collect();
ApplicationClass excel;
_Workbook xBk;
_Worksheet xSt;
excel = new ApplicationClass();
xBk = excel.Workbooks.Add(true);
xSt = (_Worksheet)xBk.ActiveSheet;
//自定义代码...
//结束时
xBk.Close(false, null, null);
excel.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(xBk);
System.Runtime.InteropServices.Marshal.ReleaseComObject(excel);
System.Runtime.InteropServices.Marshal.ReleaseComObject(xSt);
xBk = null;
excel = null;
xSt = null;