Gridview中的数据导出到word中的方法

liuchangfei 2009-12-12 08:05:19
Gridview中的数据导出到word中的方法
页面中的Gridview中的数据导出到word中的方法是怎么样?就当你点击导出按钮就开始导出???
...全文
83 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
wuyq11 2009-12-12
  • 打赏
  • 举报
回复
string style = @"<style> .text { mso-number-format:\@; } </script> ";
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=" + Server.UrlEncode("word.doc"));
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
Response.ContentType = "application/vnd.word";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
DataList1.RenderControl(htmlWrite);
Response.Write(style);
Response.Write(stringWrite.ToString());
Response.End();
public override void VerifyRenderingInServerForm(Control control)
{

}
bancxc 2009-12-12
  • 打赏
  • 举报
回复
美女?
//导出Word

protected void Button2_Click(object sender, EventArgs e)
{
Export("application/ms-word", "员工信息.doc");
}
private void Export(string FileType, string FileName)
{
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF7;
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
Response.ContentType = FileType;
this.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
GridView1.RenderControl(hw);
Response.Write(tw.ToString());
Response.End();
}

17,740

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 .NET Framework
社区管理员
  • .NET Framework社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧