protected void Button1_Click(object sender, EventArgs e)
{
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode("application / ms - excel", Encoding.UTF8).ToString());
Response.ContentType = "Employee information.xls";
this.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
GridView1.RenderControl(hw);
Response.Write(tw.ToString());
Response.End();
}
同意楼上的回答
另外一种方式就是读取Gridview的数据,然后控制Excel写入。