Web导出Word需要添加头文件

        经常导出EXCEL,上次需要导出到WORD,用原来EXCEL的方法不管用了,出现编码错误,郁闷,打开WORD文件,另存为HTML,看了一下源码,发现一段头文件,添加之后,正确导出了.
tableHeader = " <html xmlns:o=\"urn:schemas-microsoft-com:office:office\"";
                
tableHeader +="xmlns:w=\"urn:schemas-microsoft-com:office:word\"";
                tableHeader +
= "xmlns:st1=\"urn:schemas-microsoft-com:office:smarttags\"";
                tableHeader +
= "xmlns=\"http://www.w3.org/TR/REC-html40\">";
posted @ 2006-08-15 17:23 Zaluao 阅读(1249) 评论(2)  编辑 收藏 网摘 所属分类: .NET SKILL

  回复  引用  查看    
#1楼2006-08-15 18:23 | aspnetx      
这个在asp的时候我是这么做的,但是在asp.net中,还是推荐用现成的对象好,比如

HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + filename);
HttpContext.Current.Response.Charset = "UTF-8";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Default;
HttpContext.Current.Response.ContentType = filetype;

//HttpContext.Current.Response.ContentType = "application/ms-excel";//image/JPEG;text/HTML;image/GIF;vnd.ms-excel/msword

System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
gv.RenderControl(hw);

HttpContext.Current.Response.Write(tw.ToString());
HttpContext.Current.Response.End();

  回复  引用  查看    
#2楼[楼主]2006-08-15 23:50 | 尧尧      
@aspnetx
是的,我也是用现成的,这就是上面我说的,我经常导出EXCEL,那个函数我写在了
http://www.cnblogs.com/zjy/archive/2006/05/18/402991.html">Table导出为xls,doc,txt,htm方法
但如果导出WORD,就会出现编码的问题,当添了上面那段,问题就解决了:)




发表评论

昵称: [登录] [注册]

主页:

邮箱:(仅博主可见)

评论内容:

  登录  注册

[使用Ctrl+Enter键快速提交评论]

0 477651




相关文章:

相关链接: