c#中 如何将gridview中数据导出到已经存在的Excel

来源:百度知道 编辑:UC知道 时间:2024/05/15 07:16:59
我没太多的分,但尽所能给大家,对给予我帮助的人,在这我先行谢过了

把DataGrid的数据,导出到excel中
1:在页面的类中添加
public override void VerifyRenderingInServerForm(Control control)
{

}
2:写上如下代码:
Response.ContentType = "application/vnd.ms-excel";
System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
this.GridView2.RenderControl(hw);//设置你要导出内容的控件,我这里是Repeater
Response.Write(tw.ToString());
Response.End();