Two methods of exporting Excel

xiaoxiao2021-03-06  203

1, save directly into Excel

Page_load ()

{

Response.write (this.Getexcelhtml ()); respternse.contenttype = "Application / VND.MS-Excel"; response.addheader ("Content-Disposition", "Attachment; FileName = ReqForQuote.xls"); Response.end );

}

Private string getExcelhtml ()

{

String res = "

Aaabbb
aaa ...

.... ";

Return res;

}

2, output with DataGrid

Page_load ()

{

Entitiesgrid.datasource = new stockbr (). getBywhere (null, _exportpage.filtereXpression, _exportpage.sortexpression) .stock .defaultView; entitiesgrid.database ();

// set the content type = "Application / VND.ms-Excel"; // Remove the charset from the content-type header. Response.charset = ""; // Turn Off the view stat. this.EnableViewState = false; StringWriter stringWriter = new StringWriter (); HtmlTextWriter htmlTextWriter = new HtmlTextWriter (stringWriter); // Get the HTML for the control entitiesGrid.RenderControl (htmlTextWriter);. // Write the HTML back to the browser Response. .Write (StringWriter.toString ()); // end the response. Response.end ();

}

转载请注明原文地址:https://www.9cbs.com/read-128627.html

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.050, SQL: 9