将 HTML 转换为 Word 文档

2023-12-07

如何转换页面HTML to word文档。例如我有一个网页需要保存在word文档中。如何将 HTML 页面转换为 Word 文档。以及如何在word文档中插入分页符


下面您可以找到一个将 html 转换为 word 的示例。

它工作正常,我已经测试过了MS Office 2013 and Open Office.

注意:对于分页符,请插入以下行

<br clear=all style='mso-special-character:line-break;page-break-before:always'> 

Example:

Dim StrLocLetterText As StringBuilder = New StringBuilder()
Dim ObjLocHtml1 As String = "<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>"
Dim ObjLocHtml2 As String = "</body></html>"

StrLocLetterText.Append(ObjLocHtml1)
StrLocLetterText.Append(<Content within body tag>)
StrLocLetterText.Append(ObjLocHtml2)
HttpContext.Current.Response.Clear()
HttpContext.Current.Response.Charset = ""
HttpContext.Current.Response.ContentType = "application/msword"
HttpContext.Current.Response.AddHeader("Content-Disposition", "inline;filename=" + <FileName> + ".doc")
HttpContext.Current.Response.Write(StrLocLetterText)
HttpContext.Current.Response.End()
HttpContext.Current.Response.Flush()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

将 HTML 转换为 Word 文档 的相关文章

随机推荐