【发布时间】:2014-01-22 09:59:21
【问题描述】:
如何转换页面HTML to word 文档。例如,我有一个需要保存在 word 文档中的网页。如何将 HTML 页面转换为 Word 文档。以及如何在word文档中插入分页符
【问题讨论】:
如何转换页面HTML to word 文档。例如,我有一个需要保存在 word 文档中的网页。如何将 HTML 页面转换为 Word 文档。以及如何在word文档中插入分页符
【问题讨论】:
您可以在下面找到将 html 转换为 word 的示例。
它运行良好,我已经在 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()
【讨论】: