/// <Summary>
/// Export an Excel file
/// </Summary>
/// <Param name = "ds"> Dataset </Param>
/// <Param name = "FILENAME"> Excel file name (excluding the extension) </Param>
Public Static Void Toexcel (datatable DT, String Filename)
{
System. Io. stringwriter TW = New System. Io. stringwriter ();
System. Web. UI. htmltextwriter HW = New System. Web. UI. htmltextwriter (TW );
Gridview gv = New Gridview ();
GV. rowdatabound + = New Gridviewroweventhandler (gv_rowdatabound );
GV. datasource = DT;
GV. databind ();
GV. rendercontrol (HW );
System. Web. httpresponse response = System. Web. httpcontext. Current. response;
Response. Clear ();
Response. charset = " Gb2312 " ;
Response. contenttype = " Application/vnd. MS-Excel " ;
Response. appendheader ( " Content-Disposition " , " Attachment; filename = " + System. Web. httputility. urlencode (filename) + " . Xls " );
Response. Write ( " <HTML> " Content - Type \ " Content = \ " Text / HTML; charset = Gb2312 \ " > </Head> <body> " );
Response. Write (TW. tostring ());
Response. Write ( " </Body> " );
Response. End ();
HW. Close ();
HW. Flush ();
GV. Dispose ();
Tw. Close ();
Tw. Flush ();
}
/**/ /// <Summary>
/// Export a word file
/// </Summary>
/// <Param name = "ds"> Dataset </Param>
/// <Param name = "FILENAME"> Word file name (excluding the extension) </Param>
Public Static Void Toword (datatable DT, String Filename)
{
System. Io. stringwriter TW = New System. Io. stringwriter ();
System. Web. UI. htmltextwriter HW = New System. Web. UI. htmltextwriter (TW );
Gridview gv = New Gridview ();
GV. rowdatabound + = New Gridviewroweventhandler (gv_rowdatabound );
GV. datasource = DT;
GV. databind ();
GV. rendercontrol (HW );
System. Web. httpresponse response = System. Web. httpcontext. Current. response;
Response. Clear ();
Response. charset = " Gb2312 " ;
Response. contenttype = " Application/MS-word " ;
Response. appendheader ( " Content-Disposition " , " Attachment; filename = " + System. Web. httputility. urlencode (filename) + " . Doc " );
Response. Write ( " <HTML> " Content - Type \ " Content = \ " Text / HTML; charset = Gb2312 \ " > </Head> <body> " );
Response. Write (TW. tostring ());
Response. Write ( " </Body> " );
response. end ();
HW. close ();
HW. flush ();
GV. dispose ();
TW. close ();
TW. flush ();
}