|
/// <summary>
/// export to Excel
/// </ summary>
/// <param name = "sender"> </ param>
/// <param name = "e"> </ param>
private void Button1_Click (object sender, System.EventArgs e)
{
Response.Clear ();
Response.Buffer = true;
Response.Charset = "GB2312";
Response.AppendHeader ("Content-Disposition", "attachment; filename = FileName.xls");
Response.ContentEncoding = System.Text.Encoding.GetEncoding ("GB2312"); // Set the output stream to Simplified Chinese
Response.ContentType = "application / ms-excel"; // Set the output file type to an excel file.
this.EnableViewState = false;
System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo ("ZH-CN", true);
System.IO.StringWriter oStringWriter = new System.IO.StringWriter (myCItrad);
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter (oStringWriter);
this.DataGrid1.RenderControl (oHtmlTextWriter);
Response.Write (oStringWriter.ToString ());
Response.End ();
} |
|