2014-01-22 2 views
1

Как преобразовать страницу HTML to word документ. Например, у меня есть веб-страница, которую мне нужно сохранить в текстовом документе. Как конвертировать HTML-страницу в Word Document. И как вставить разрыв страницы в документе WordПреобразование HTML в документ Word

ответ

2

Ниже вы можете найти пример для преобразования 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() 
Смежные вопросы