我尝试将带格式的文本插入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格式作为我的字符串,但这是相同的行为。
发布于 2011-07-05 21:10:42
我最后给出了一个“不太好”的解决方案:
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格式),所以在接受这个答案之前,我会等待……
https://stackoverflow.com/questions/6579465
复制相似问题