【问题标题】:Convert RTF embedded OLE to HTML in Access in VBA在 VBA 中的 Access 中将 RTF 嵌入式 OLE 转换为 HTML
【发布时间】:2020-04-06 05:12:27
【问题描述】:

我有一个包含 RichText 格式数据的嵌入式 OLE 字段的表。我需要将此数据传输到 MySQL 数据库并将其转换为 HTML。我使用访问。有没有办法在 VBA 中快速完成? 我在网上搜索,大多数人使用 RichText 控件(richtx32.ocx)来获取纯文本,但我需要它保持格式化,我也没有这个控件。

【问题讨论】:

  • 您是否尝试过使用 RichText=True 的常规文本框?它将数据保存为 HTML(HTML 的一小部分)。

标签: html vba ms-access rtf converters


【解决方案1】:

这是我解决问题的方法:

Option Explicit
Public wrd As Word.Application
Public doc As Word.Document

Function RTF2HTMLviaWord(rtf As String) As String
    'Open Tools --> References --> and check Microsoft Scripting Runtime

    Dim fso As New FileSystemObject
    Dim text As TextStream
    Dim temp As String
    temp = Environ("TEMP")

    If Len(rtf) > 1 Then
        Set text = fso.CreateTextFile(temp & "\RTF2HTML.rtf", True)
        text.Write rtf
        text.Close
        If wrd Is Nothing Then
            Set wrd = New Word.Application
        End If

        Set doc = wrd.Documents.Open(temp & "\RTF2HTML.rtf", False)
        doc.SaveAs temp & "\RTF2HTML.htm", wdFormatHTML
        doc.Close
        fso.DeleteFile temp & "\RTF2HTML.rtf"

        Set text = fso.OpenTextFile(temp & "\RTF2HTML.htm", ForReading, False)
        RTF2HTMLviaWord = text.ReadAll
        text.Close
        fso.DeleteFile temp & "\RTF2HTML.htm"
    Else
        RTF2HTMLviaWord = ""
    End If

End Function

唯一的缺点是 Word 产生了太多垃圾 HT​​ML 标签。我希望它可以在不格式化的情况下保存最少的 HTML 标记。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-11-15
    • 2012-02-17
    • 2014-04-18
    • 1970-01-01
    • 2015-11-20
    • 1970-01-01
    • 1970-01-01
    • 2012-06-18
    相关资源
    最近更新 更多