asp.net automatically closes the Excel process code when the XLS file is finished

Source: Internet
Author: User

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
{ }
}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.