Javascript 将文本从HTML转换为MS Word
我正在尝试将HTML(从CK编辑器)转换为MS Word:Javascript 将文本从HTML转换为MS Word,javascript,html,ms-word,Javascript,Html,Ms Word,我正在尝试将HTML(从CK编辑器)转换为MS Word: wordDoc = new ActiveXObject("Word.Application"); 但结果显示Word文档中的所有HTML标记(如span,strong) 如何解决这个问题?有一些完整的解决方案。试试这些: 当您在寻找WORD解决方案时,PDF解决方案也可以吗?如果有的话,试试看。但同样,如果你一定要有文字作为最终结果,这是行不通的。除非您需要用户在文档上键入内容,否则PDF通常会更好,因为它们可以防止用户修改
wordDoc = new ActiveXObject("Word.Application");
但结果显示Word文档中的所有HTML标记(如span
,strong
)
如何解决这个问题?有一些完整的解决方案。试试这些:
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
受保护的子CreateHTMlToWord()
尝试
将sHtml作为新的StringBuilder进行调整
Dim htmlForm作为新的htmlForm
grdHTMLData.GridLines=网格线。两个网格视图都用数据填充
Response.ClearContent()
AddHeader(“内容处置”、“附件;文件名=estPage.doc”)
Response.ContentType=“应用程序/vnd.doc”
Dim str作为新IO.StringWriter
Dim htex作为新的HtmlTextWriter(str)
添加(grdHTMLData)
htmlForm.EnableViewState=False
Me.Controls.Add(htmlForm)
htmlForm.RenderControl(htex)
sHtml.Append(“”)
sHtml.Append(“”)
sHtml.Append(“”)
sHtml.Append(“.mGrid{width:100%;背景色:#F8FCFE;边距:5px 0 10px 0;边框折叠:折叠;}”)
sHtml.Append(“.mGrid td{padding:2px;color:black;}.mGrid td a:link{color:#000;}”)
sHtml.Append(“.mGrid th{padding:4px2px;颜色:#fff;背景:#4A7298;字体大小: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{边框宽度:0;字体重量:粗体;颜色:#666;行高:12px;}”)
sHtml.Append(“.mGrid.pgr td a{color:#666;}.mGrid.pgr td a:link{color:#4A7298;padding:0 5px;文本装饰:下划线;}”)
sHtml.Append(“.mGrid.pgr td a:active{text-decoration:none;font-weight:bold;}”)
sHtml.Append(“.mGrid.pgr td a:hover{color:#fff;背景色:#4A7298;文本装饰:无;}.mGrid a:hover{text装饰:下划线;}”)
sHtml.Append(“.mGridHdr th{text align:left;}”)
sHtml.Append(“”)
sHtml.Append(“”)
sHtml.Append(“”)
sHtml.Append(str.ToString)
sHtml.Append(“”)
sHtml.Append(“”)
Response.Write(sHtml.ToString)
Response.Flush()
答复:Close()
特例
结束尝试
端接头
允许在html和word文档(以及许多其他格式)之间进行转换。
Pandoc是一个haskel库,但所有平台都有捆绑安装程序。要转换文档,您需要使用此命令
pandoc -o file.doc file.html
我能想象的是如下步骤:
你能发布完整的代码吗?如果你能从CK编辑器的输出中生成格式良好的XHTML,并且能自如地使用Java,那么docx4j可能会有所帮助。有趣的事实:如果你将一个名为test.html的文件重命名为test.doc,并且它是一个完整的html文档,双击该文件将按预期在word中打开它,格式化,WYSIWYG等等。这关系到你的目标是MS Word的哪个版本@如果您的用户在>2007上,则dandavis是正确的。