我试图将HTML(来自CK Editor)转换为MS Word:
wordDoc = new ActiveXObject("Word.Application");
但结果显示在 Word 文档中出现了所有的 HTML 标签(如
span
,strong
)。我该如何解决这个问题?
我试图将HTML(来自CK Editor)转换为MS Word:
wordDoc = new ActiveXObject("Word.Application");
span
,strong
)。Pandoc 允许在多种格式之间进行转换,包括 HTML 和 Word 文档。 Pandoc 是一个 Haskell 库,但是也有适用于所有平台的捆绑安装程序。要转换您的文档,您需要使用以下命令。
pandoc -o file.doc file.html
如果您正在寻找WORD解决方案,那么PDF解决方案是否也可以?如果是这样,请尝试http://www.fpdf.org。但是,如果您绝对需要WORD作为最终结果,则此方法无效。除非您需要用户在文档上键入内容,否则通常情况下PDF更好,因为它们可以防止用户进行修改。
Protected Sub CreateHTMlToWord()
Try
Dim sHtml As New StringBuilder
Dim htmlForm As New HtmlForm
grdHTMLData.GridLines = GridLines.Both 'Grid View Fill with data
Response.ClearContent()
Response.AddHeader("content-disposition", "attachment; filename=estPage.doc")
Response.ContentType = "application/vnd.doc"
Dim str As New IO.StringWriter
Dim htex As New HtmlTextWriter(str)
htmlForm.Controls.Add(grdHTMLData)
htmlForm.EnableViewState = False
Me.Controls.Add(htmlForm)
htmlForm.RenderControl(htex)
sHtml.Append("<html>")
sHtml.Append("<head>")
sHtml.Append("<style type='text/css'>")
sHtml.Append(".mGrid{width: 100%; background-color: #F8FCFE; margin: 5px 0 10px 0; border-collapse: collapse;}")
sHtml.Append(".mGrid td{ padding: 2px; color: black;} .mGrid td a:link{ color: #000;}")
sHtml.Append(".mGrid th{ padding: 4px 2px; color: #fff; background: #4A7298; font-size: 0.9em;}")
sHtml.Append(".mGrid th a:link{ color: #fff; font-weight: bold;} .mGrid .alt{ background-color: #E1EEF7;}")
sHtml.Append(".mGrid .pgr{ background: #E1EEF7;} .mGrid .pgr table{ margin: 5px 0;}")
sHtml.Append(".mGrid .pgr td span{ border-width: 0; font-weight: bold; color: #666; line-height: 12px;}")
sHtml.Append(".mGrid .pgr td a{ color: #666;} .mGrid .pgr td a:link{ color: #4A7298; padding: 0 5px; text-decoration: underline;}")
sHtml.Append(".mGrid .pgr td a:active{ text-decoration: none; font-weight: bold;}")
sHtml.Append(".mGrid .pgr td a:hover{ color: #fff; background-color: #4A7298; text-decoration: none;} .mGrid a:hover{ text-decoration: underline;}")
sHtml.Append(".mGridHdr th{ text-align: left;}")
sHtml.Append("</style>")
sHtml.Append("</head>")
sHtml.Append("<body>")
sHtml.Append(str.ToString)
sHtml.Append("</body>")
sHtml.Append("</html>")
Response.Write(sHtml.ToString)
Response.Flush()
Response.Close()
Catch ex As Exception
End Try
End Sub