如何转换页面HTML to word
文档。例如,我有一个网页,我需要保存在word文档中。如何将HTML页面转换为Word文档。以及如何在word文档中插入分页符
答案 0 :(得分:3)
下面你可以找到一个将html转换为单词的例子。
它工作正常,我在MS Office 2013
和Open Office
进行了测试。
注意:对于行下面的分页符插入
<br clear=all style='mso-special-character:line-break;page-break-before:always'>
示例:
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()