【问题标题】:Insert HTML or RTF formatted text into Word Bookmark将 HTML 或 RTF 格式的文本插入 Word 书签
【发布时间】:2011-07-05 07:53:13
【问题描述】:

我尝试将格式化文本插入 Word 书签。文本来自几个富文本控件(我们使用 TX 文本控件)并附加到书签中。 问题是标签是按原样编写的,没有被解释。

oWord = New Word.Application
Dim strFileName As String = "\\...\Template.dot"
oDoc = oWord.Documents.Add(strFileName)
Dim strText As String = ""
Dim strOut As String = ""
txtPart1.Save(strOut, TXTextControl.StringStreamType.RichTextFormat)
strText += strOut
strText += ControlChars.CrLf & ControlChars.CrLf & ControlChars.CrLf
strText += txtPart2.Text
oDoc.Bookmarks.Item("Conditions").Range.Text = strText
oWord.Visible = True

我尝试为我的字符串使用 RTF 或 HTML 格式,但行为相同。

【问题讨论】:

    标签: vb.net ms-word bookmarks


    【解决方案1】:

    我完成了一个“不太好”的解决方案:

    oWord = New Word.Application
    Dim strFileName As String = "\\...\Template.dot"
    oDoc = oWord.Documents.Add(strFileName)
    Dim strText As String = ""
    txtPart1.Save(strText, TXTextControl.StringStreamType.RichTextFormat)
    Clipboard.SetData(DataFormats.Rtf, strText)
    oDoc.Bookmarks.Item("Conditions").Range.PasteSpecial(DataType:=Word.WdPasteDataType.wdPasteRTF)
    

    我讨厌使用剪贴板插入我的格式化文本(RTF 格式,它似乎不适用于 HTML 格式)的想法,所以我会在接受这个答案之前等待......

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-20
      • 1970-01-01
      • 1970-01-01
      • 2011-12-30
      • 2023-03-21
      • 1970-01-01
      • 1970-01-01
      • 2015-11-20
      相关资源
      最近更新 更多