Using system;
Using system. configuration;
Using system. Data;
Using system. LINQ;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. htmlcontrols;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using system. xml. LINQ;
Using system. IO;
Using system. text;
Public partial class _ default: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{
Datatable tab = new datatable ();
Tab. Columns. Add ("");
Tab. Columns. Add ("B ");
Datarow row1 = tab. newrow ();
Row1 ["A"] = "cwg ";
Row1 ["B"] = "afsd ";
Tab. Rows. Add (row1 );
Datarow row2 = tab. newrow ();
Row2 ["A"] = "this is Chinese ";
Row2 ["B"] = "this is Chinese ";
Tab. Rows. Add (row2 );
Datarow row3 = tab. newrow ();
Row3 ["A"] = "this is Chinese ";
Row3 ["B"] = "this is Chinese ";
Tab. Rows. Add (row3 );
Datarow row4 = tab. newrow ();
Row4 ["A"] = "this is Chinese ";
Row4 ["B"] = "this is Chinese ";
Tab. Rows. Add (row4 );
Exportexcel1 (Tab );
}
/// <Summary>
/// Export the exlce table
/// </Summary>
/// <Param name = "ds"> </param>
Private void exportexcel1 (datatable DS)
{
Response. Clear ();
Response. addheader ("content-disposition", "online?filename=exportname.xls ");
Response. contenttype = "Appilication/vnd. MS-excel ";
// Sets the text output encoding.
Response. contentencoding = system. Text. encoding. getencoding ("gb2312 ");
// Response. charset = "";
Stringbuilder builer = new stringbuilder ();
System. Io. stringwriter Sw = new system. Io. stringwriter (builer );
Htmltextwriter HTW = new htmltextwriter (SW );
Gridview DG = new gridview ();
DG. datasource = Ds;
DG. databind ();
DG. rendercontrol (HTW );
Response. Write (SW. tostring ());
Response. End ();
}
}