将 HTML 转换为单词格式
本文关键字:单词 格式 转换 HTML | 更新日期: 2023-09-27 18:32:15
我使用单词自动化来创建word文档。我想在该文件中嵌入一些 html 代码。我应该如何将 html 标签转换为 Word 文档格式?(我想在html中保留字体,粗体,表格和其他样式)
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Charset = "";
HttpContext.Current.Response.ContentType = "application/msword";
string strFileName = "docName" + ".doc";
HttpContext.Current.Response.AddHeader("Content-Disposition", "inline;filename=" + strFileName);
StringBuilder strHTMLContent = new StringBuilder();
strHTMLContent.Append("<html xmlns:v='"urn:schemas-microsoft-com:vml'" xmlns:o='"urn:schemas-microsoft-com:office:office'" xmlns:x='"urn:schemas-microsoft-com:office:word'" xmlns='"http://www.w3.org/TR/REC-html40'"><head></head><body>");
strHTMLContent.Append(htmlContent);
strHTMLContent.Append("</body></html>");
HttpContext.Current.Response.Write(strHTMLContent);
HttpContext.Current.Response.End();
HttpContext.Current.Response.Flush();