// Convert the HTML table content into a string stream
/* Cache the original table data */
System. Text. stringbuilder reportcontents = new system. Text. stringbuilder ();
System. Web. UI. htmltextwriter reportwriter = new htmltextwriter (new system. Io. stringwriter (reportcontents ));
// Tabreport is the displayed htmltable
Tabreport. rendercontrol (reportwriter );
Viewstate ["report_contents"] = reportcontents;
/* Cache completed */
// Write the string stream to the excle table
String sexportname = "report name"
System. Text. stringbuilder reportcontents = viewstate ["report_contents"] As system. Text. stringbuilder;
Response. contenttype = "application/vnd. MS-excel ";
Response. contentencoding = system. Text. encoding. utf8;
Response. addheader ("content-disposition", "attachment; filename =" + server. urlencode (sexportname) + ". xls ");
Response. Output. Write (reportcontents. tostring ());
Response. End ();