推荐十个网站,地产公司网站建设,九江哪家网站建设公司好,什么样的网站需要icp经营性备案ASP.NET导出word实例 最近遇到一个题目就是如何在asp.net中将数据导出到word中#xff0c;由于数据是动态的#xff0c;所以需要在后台拼出想要的的格式#xff0c;翻遍了网页找出了一个比较满意的代码#xff0c;感谢那位高手。代码如下#xff1a; public void Download… ASP.NET导出word实例 最近遇到一个题目就是如何在asp.net中将数据导出到word中由于数据是动态的所以需要在后台拼出想要的的格式翻遍了网页找出了一个比较满意的代码感谢那位高手。代码如下 public void Download(){Random rd new Random();string fileName DateTime.Now.ToString(yyyyMMddhhmm) rd.Next() .doc;//存储路径string path Server.MapPath(fileName);//创建字符输出流StreamWriter sw new StreamWriter(path, true, System.Text.UnicodeEncoding.UTF8);//需要导出的内容// string str htmlheadtitle无标题文档/title/headbody这里放从数据库导出的word文档内容/body/html;string str ;str htmlheadtitle无标题文档/title/headbody;str div阅读报表/div;str table border1tr;str td20000/td;str td10000/td/trtr;str td30000/td;str td30000/tdtr;str /table/body/html;//写入sw.Write(str);sw.Close();Response.Clear();Response.Buffer true;this.EnableViewState false;Response.Charset utf-8;Response.AppendHeader(Content-Disposition, attachment;filename HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));Response.ContentType application/octet-stream;Response.WriteFile(path);Response.Flush();Response.Close();Response.End();}