GridView1中的数据导出到excel。用C#.net完全实现了???? 怎么实现的

2024-12-05 12:18:38
推荐回答(2个)
回答1:

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();
}

回答2:

同意楼上的回答
另外一种方式就是读取Gridview的数据,然后控制Excel写入。