vb.net 将 HTML 转换为 Word 文档
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21279611/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Convert HTML To Word Document
提问by Indranil.Bharambe
How to convert page HTML to worddocument. For example i have a web page which i need to save in word document. How to convert HTML Page to Word Document. And how to insert Page break in word document
如何转换页面HTML to word文档。例如,我有一个网页,我需要将其保存在 Word 文档中。如何将 HTML 页面转换为 Word 文档。以及如何在word文档中插入分页符
回答by Indranil.Bharambe
Below you can find an example to convert html to word.
您可以在下面找到将 html 转换为 word 的示例。
It works fine and i had tested it on MS Office 2013and Open Office.
它工作正常,我已经在MS Office 2013和 上对其进行了测试Open Office。
Note : For page break insert below line
注意:对于分页符在行下方插入
<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()

