如何将ASP.NET实例导出为Word文档实现长尾关键词优化?
- 内容介绍
- 文章标签
- 相关推荐
本文共计436个文字,预计阅读时间需要2分钟。
最近遇到一个课题,就是如何在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 = "<html><head><title>无标题文档</title></head><body>这里放从数据库导出的word文档内容</body></html>"; string str = ""; str += "<html><head><title>无标题文档</title></head><body>"; str += "<div>阅读报表</div>"; str += "<table border='1'><tr>"; str += "<td>20000</td>"; str += "<td>10000</td></tr><tr>"; str += "<td>30000</td>"; str += "<td>30000</td><tr>"; 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(); }
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持易盾网络!
本文共计436个文字,预计阅读时间需要2分钟。
最近遇到一个课题,就是如何在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 = "<html><head><title>无标题文档</title></head><body>这里放从数据库导出的word文档内容</body></html>"; string str = ""; str += "<html><head><title>无标题文档</title></head><body>"; str += "<div>阅读报表</div>"; str += "<table border='1'><tr>"; str += "<td>20000</td>"; str += "<td>10000</td></tr><tr>"; str += "<td>30000</td>"; str += "<td>30000</td><tr>"; 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(); }
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持易盾网络!

