2014-01-22 158 views
1

如何轉換頁面HTML to word文檔。例如,我有一個網頁,我需要保存在Word文檔中。如何將HTML頁面轉換爲Word文檔。以及如何在Word文檔中插入分頁符將HTML轉換爲Word文檔

回答

2

以下您可以找到將html轉換爲word的示例。

它工作正常,我已在MS Office 2013Open 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()