The excel Process Code is automatically closed after the xls file is generated by asp.net.

Source: Internet
Author: User

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

}

Related Article

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.