ASP tutorials automatically close the Excel process code when the. NET build xls file completes
Method One
Gc.collect ();
ApplicationClass Excel;
_workbook XBK;
_worksheet xst;
Excel = new ApplicationClass ();
XBK = Excel.workbooks.add (true);
Xst = (_worksheet) xbk.activesheet;
Custom code ...
At the end
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 Two
Finally
{
((microexcel._application) tempapp). Workbooks.close ();
Int32 tempgeneration = Gc.getgeneration (Tempapp);
((microexcel._application) Tempapp). Quit ();
Gc.collect (tempgeneration);
The above section has already killed the Excel process in WinForm, but not in the ASP.net tutorial
Process[] myprocesses;
myprocesses = Process.getprocessesbyname ("Excel");
//No Excel process ID, Only process start time can be judged temporarily
foreach (Process myprocess in myprocesses)
{
Try
{
datetime starttime = Myprocess.starttime;
if (starttime >= tempstart && starttime <= tempend)
{
Myprocess.kill ();
}
}//to run a Web page directly in VS, there's no question of StartTime.
catch//There are some core processes that are not allowed to be accessed, so the exception that is caused can catch and discard processing
{ }
}
}