且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将RTF(RTF格式)代码转换为Excel中的纯文本

更新时间:2023-10-06 08:51:10

另一个选择可以是使用Microsoft Rich Textbox Control(但不能在x64 Office上测试)

  Sub rtfToText()
使用CreateObject(RICHTEXT.RichtextCtrl)或添加对Microsoft Rich Textbox控件的引用,以便早期绑定和使用新的RichTextLib.RichTextBox
.SelStart = 0'需要被选择
.TextRTF = Join(Application.Transpose(Cells.CurrentRegion.Columns(1)))
[C1] = .Text '设置目标单元格

'或者如果你想要它们在单独的单元格中:
a =拆分(.Text,vbNewLine)
范围(C3)。调整大小(UBound (a)+ 1)= Application.Transpose(a)
End with
End Sub


I exporting a database query as Excel and I am getting rows with RTF formatting.

How can I convert these fields into plain text? I've found answers that are pretty old, so I was wondering if anyone knows a way.

Another alternative can be using Microsoft Rich Textbox Control (but can't test it on x64 Office)

Sub rtfToText()
    With CreateObject("RICHTEXT.RichtextCtrl") ' or add reference to Microsoft Rich Textbox Control for early binding and With New RichTextLib.RichTextBox
        .SelStart = 0                          ' needs to be selected
        .TextRTF = Join(Application.Transpose(Cells.CurrentRegion.Columns(1)))
        [C1] = .Text                           ' set the destination cell here

        ' or if you want them in separate cells:
        a = Split(.Text, vbNewLine)
        Range("C3").Resize(UBound(a) + 1) = Application.Transpose(a)
    End With
End Sub