protected void Button1_Click(object sender, EventArgs e)
{
GridView1.AllowPaging = false;
GridView1.DataBind();
GridView1.DataSource = (DataTable)ViewState["ExportTable"];
string excelFileName = "Result.xls";
Response.Clear();
Context.Response.AddHeader("content-disposition", "attachment;filename=" +
Server.UrlEncode(excelFileName));
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Context.Response.ContentType = "application/vnd.xls";
Response.Charset = "utf-8"; // "big5";
System.IO.StringWriter tw = new System.IO.StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
this.GridView1.RenderControl(hw);
Context.Response.Write(tw.ToString().Replace("", "").Replace("", ""));
Context.Response.End();
GridView1.AllowPaging = true;
GridView1.DataBind();
}
沒有留言:
張貼留言