我正在尝试将HTML (从CK编辑器)转换为MS Word:
wordDoc = new ActiveXObject("Word.Application");
但结果显示Word文档中的所有HTML标记(如span
、strong
)。
我该如何解决这个问题?
发布于 2013-05-20 16:36:14
发布于 2013-05-22 21:59:07
当您正在寻找WORD解决方案时,PDF解决方案也可以吗?如果是这样,请尝试使用http://www.fpdf.org。但同样,如果你一定要把单词作为最终结果,这是行不通的。除非您需要用户在文档上键入内容,否则PDF通常更好,因为它们可以防止用户修改。
发布于 2013-05-23 19:21:53
根据您的问题,我了解到您希望HTML与Word的所有样式(Css适用)
我有这样的需求,我在下面的代码中实现了它,它对我来说是正确的。请检查下面的代码,这可能是它的全部帮助
在这里,我从GridView创建Word文件,并将样式应用到网格。它在Word文件中创建与在browser.you中显示相同网格,只需为您的工作更改样式(css)相关标签。
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
https://stackoverflow.com/questions/14706436
复制相似问题