将 HTML 或 RTF 格式的文本插入 Word 书签
我尝试将格式化文本插入 Word 书签。文本来自多个富文本控件(我们使用 TX Text Control)并附加到书签中。 问题在于标签是按原样编写的并且没有被解释。
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 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
I tried with RTF or HTML format for my string but it is the same behavior.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我完成了一个“不太好的”解决方案:
我讨厌使用剪贴板插入格式化文本的想法(RTF格式,它似乎不适用于HTML格式),所以我会等待再接受这个答案......
I finished with a "not so good" solution :
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...