asp.net|excel|word| Data | page
Implemented in the following button click events:
private void Btnmime_click (object sender, System.EventArgs e)
{
Binddata ();
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader ("Content-disposition", "inline;filename=")
+ httputility.urlencode ("Download file. xls", Encoding.UTF8));
If the output is word, modify to the following code
Response.ContentType = "Application/ms-word"
Response.AddHeader ("Content-disposition", "Inline;filename=test.doc")
StringBuilder sb=new StringBuilder ();
System.IO.StringWriter SW = new System.IO.StringWriter (SB);
System.Web.UI.HtmlTextWriter HW = new System.Web.UI.HtmlTextWriter (SW);
Sb. Append ("Dgshow.rendercontrol (HW);
Sb. Append ("</body>Response.Write (sb.) ToString ());
Response.End ();
}
Note: 1. If there is a button column in the DataGrid, it should be hidden before exporting.
2. If the DataGrid has pagination, but also print all the data, you should first cancel the paging.