The excel Process Code is automatically closed after the xls file is generated by asp.net.
Asp tutorial. net automatically closes the excel Process Code after the xls file is generated
// Method 1
Gc. collect ();
Applicationclass excel;
_ Workbook xbk;
_ Worksheet xst;
Excel = new applicationclass ();
Xbk = excel. workbooks. add (true );
Xst = (_ worksheet) xbk. activesheet;
// Custom code...
// End Time
Xbk. close (false, null, null );
Excel. quit ();
System. runtime. interops tutorial ervices. marshal. releasecomobject (xbk );
System. runtime. interopservices. marshal. releasecomobject (excel );
System. runtime. interopservices. marshal. releasecomobject (xst );
Xbk = null;
Excel = null;
Xst = null;
// Method 2
Finally
{
(Microexcel. _ application) tempapp). workbooks. close ();
Int32 tempgeneration = gc. getgeneration (tempapp );
(Microexcel. _ application) tempapp). quit ();
Gc. collect (tempgeneration );
// The above section has killed the excel process in winform, but it does not work in the asp.net tutorial.
Process [] myprocesses;
Myprocesses = process. getprocessesbyname ("excel ");
// The excel process id is not obtained. Currently, only the process start time can be determined.
Foreach (process myprocess in myprocesses)
{
Try
{
Datetime starttime = myprocess. starttime;
If (starttime> = tempstart & starttime <= tempend)
{
Myprocess. kill ();
}
} // Running the webpage directly in vs does not result in the failure to get starttime.
Catch // some core processes are not allowed to access, so exceptions can be caught and discarded.
{}
}
}