首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >将文本从HTML转换为MS Word

将文本从HTML转换为MS Word
EN

Stack Overflow用户
提问于 2013-02-05 19:26:38
回答 5查看 3.3K关注 0票数 6

我正在尝试将HTML (从CK编辑器)转换为MS Word:

代码语言:javascript
运行
复制
wordDoc = new ActiveXObject("Word.Application");

但结果显示Word文档中的所有HTML标记(如spanstrong)。

我该如何解决这个问题?

EN

回答 5

Stack Overflow用户

发布于 2013-05-20 16:36:14

Stack Overflow用户

发布于 2013-05-22 21:59:07

当您正在寻找WORD解决方案时,PDF解决方案也可以吗?如果是这样,请尝试使用http://www.fpdf.org。但同样,如果你一定要把单词作为最终结果,这是行不通的。除非您需要用户在文档上键入内容,否则PDF通常更好,因为它们可以防止用户修改。

票数 0
EN

Stack Overflow用户

发布于 2013-05-23 19:21:53

根据您的问题,我了解到您希望HTML与Word的所有样式(Css适用)

我有这样的需求,我在下面的代码中实现了它,它对我来说是正确的。请检查下面的代码,这可能是它的全部帮助

在这里,我从GridView创建Word文件,并将样式应用到网格。它在Word文件中创建与在browser.you中显示相同网格,只需为您的工作更改样式(css)相关标签。

代码语言:javascript
运行
复制
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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14706436

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档