持续完善 Pinda.cn 秒建营销活动 通过低代码 零代码的模式快速创建营销活动,欢迎使用 。

DataGrid导出到Word/Excel文档

将DataGrid数据导出到Word文档

private void ExportToWord_Click(object sender, System.EventArgs e)
{
 Response.Clear();
 Response.AddHeader("content-disposition", "attachment;filename=FileName.doc");
 Response.Charset = "";
 Response.Cache.SetCacheability(HttpCacheability.NoCache);
 Response.ContentType = "application/vnd.word";
 System.IO.StringWriter stringWrite = new System.IO.StringWriter();
 System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
 dgDevice.RenderControl(htmlWrite);
 Response.Write(stringWrite.ToString());
 Response.End();
}

将DataGrid数据导出到Excel文档

private void ExportToExcel_Click(object sender, System.EventArgs e)
{
 Response.Clear();
 Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");
 Response.Charset = "";
 Response.Cache.SetCacheability(HttpCacheability.NoCache);
 Response.ContentType = "application/vnd.xls";
 System.IO.StringWriter stringWrite = new System.IO.StringWriter();
 System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
 dgDevice.RenderControl(htmlWrite);
 Response.Write(stringWrite.ToString());
 Response.End();
}

posted @ 2006-05-31 13:57  工具人Kim哥  阅读(333)  评论(0编辑  收藏  举报
持续完善 Pinda.cn 秒建营销活动 通过低代码 零代码的模式快速创建营销活动,欢迎使用 。