将HTML或RTF格式的文本插入Word书签 [英] Insert HTML or RTF formatted text into Word Bookmark
问题描述
我尝试将带格式的文本插入Word书签.文本来自多个富文本控件(我们使用TX文本控件),并附加到书签中. 问题在于这些标签是按原样编写的,不会被解释.
I try to insert formatted text into Word bookmarks. The text comes from several rich text controls (we use TX Text Control) and is appended into a bookmark. The problem is that the tags are written as-is and are not interpreted.
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格式输入字符串,但这是相同的行为.
I tried with RTF or HTML format for my string but it is the same behavior.
推荐答案
我完成了一个不太好"的解决方案:
I finished with a "not so good" solution :
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格式)的想法,因此我将等待接受此答案...
I hate the idea of using the clipboard to insert my formatted text (in RTF format, it seems not to work with HTML format), so I will wait before accepting this answer...
这篇关于将HTML或RTF格式的文本插入Word书签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!