62,041
社区成员
发帖
与我相关
我的任务
分享
private IntPtr GetProcessHandle
{
get { return (IntPtr)ViewState["ProcessHandle"]; }
set { ViewState["ProcessHandle"] = value; }
}
private int GetProcessID
{
get { return (int)ViewState["ProcessID"]; }
set { ViewState["ProcessID"] = value; }
}
protected void Button1_Click(object sender, EventArgs e)
{
Process process = Process.GetCurrentProcess();
process.StartInfo.FileName = Server.MapPath("wahaha/mp932.xls");
process.StartInfo.UseShellExecute = false;
process.Start();//当打开的Excel大于1个时 就报错 不是有效的win32程序
GetProcessHandle = process.Handle;
GetProcessID = process.Id;
}
private void KillPreocess(int processID)
{
Process p = Process.GetProcessById(processID);
p.Kill();
}
protected void Button2_Click(object sender, EventArgs e)
{
KillPreocess(GetProcessID);
}
finally
{
workBooks.Close();
if (xlsApp != null)
{
xlsApp.Workbooks.Close();
xlsApp.Quit();
int gc = GC.GetGeneration(xlsApp);
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlsApp);
xlsApp = null;
GC.Collect(gc);
}
GC.Collect();
}