当前位置:首页 > asp.net 将HTML导出为word的方法

asp.net 将HTML导出为word的方法

点击次数:4522  更新日期:2014-10-22

将html导出为word,只需要将header修改一下就可以了,代码如下:


Response.AppendHeader("Content-Disposition","attachment;filename=result.doc"); 

Response.ContentType = "application/ms-word"; 

Response.Charset = "UTF-8";   

Response.ContentEncoding = System.Text.Encoding.UTF8;

Response.Write("<html xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:w=\"urn:schemas-microsoft-com:office:word\" xmlns:m=\"http://schemas.microsoft.com/office/2004/12/omml\" xmlns=\"http://www.w3.org/TR/REC-html40\">");

Response.Write("<p>网页内容</p>"); 

Response.Write("</html>");

Response.End(); 


注:不加上黄色标注的部分,office打开后会出现html源代码。