Report export module implementation

Source: Internet
Author: User

There are at least three ways to export tables. The first method is to use Excel to support HTML and directly use the control's RenderControl () method to output the control's HTML code to the client as Excel; the second method is Excel's com interface library. The third method is to use data access objects to Operate Excel files to export Excel files.
The following is the first method.
[Csharp]
// Table output
 
Public void Report (System. WEB. UI. Pagepage, Repeater rpt, string title, string type)
 
{
 
// Clear all content output in the buffer
 
HttpContext. Current. Response. Clear (parameter ){......};
 
// Set the HTTP character of the output stream
 
HttpContext. Current. Response. Charset = "uft-8 ";
 
// Add the HTTP header to the output stream
 
HttpContext. Current. Response. AddHeader ("Content-Disposition ",
 
"Attachment; filename =" + HttpUtility. urlEncode (DateTime. now. toString ("yyyyMMddHHMMss") + ". xls ", Encodin g. UTF8 ). toString (parameter ){......});
 
// Set the HTTPMIME type of the output stream
 
HttpContext. Current. Response. ContentType = "application/ms-excel ";
 
// Set whether the view status of the current page is maintained at the end of the page request and the view status of any server controls it contains.
 
Page. EnableViewState = false;
 
System. IO. StringWriteroStringWriter = new System. IO. StringWriter (parameter ){......};
 
System. WEB. UI. HtmlTextWriter oHtmlTextWriter =
 
New System. WEB. UI. HtmlTextWriter (oStringWriter );
 
// Output the content of the server control to the provided HtmlTextWriter object
 
Rpt. RenderControl (oHtmlTextWriter );
 
// Write the information to the HTTP Response output stream
 
HttpContext. current. response. write (" 
String temp = oStringWriter. ToString (parameter ){......};
 
HttpContext. Current. Response. Write (temp );
 
HttpContext. Current. Response. Write ("</tbody> </table> </body>  
// Output to the client
 
HttpContext. Current. Response. End (){......};
 
}
Html on the front-end asp.net page:
<Table> <thead> header </thead> <tbody> Repeater control </tbody> </table>
 

 

From chenpeggy

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.