要回答我的問題: 我的案件創建用戶文檔樣式更新顯示並保存爲PDF格式,但我並不想依靠辦公室是在我們的應用服務器。
所以我解決了這個在我的情況下,通過使用完整的「doc.RTF」文件並導入作爲內存流/字符串,並應用我所需的更新值。
即VB。淨片斷例如
Using uStream = Assembly.GetExecutingAssembly.GetManifestResourceStream("Resourcefilepath.rtf")
Using mStream As system.IO.MemoeryStream = New MemoryStream()
uStream.CopyTo(mStream)
rtfstring = Encoding.UTF8.GetSTring(mStream.toArray())
'--Do the updates to the needed string as needed:
rtfstring.Replace("Value","UpdatedValue")
'--Load Property Memory String this method is returnind
RTFDataProperty = New MemoryStream(Encoding.UTF8.GetBytes(rtfstring))
End Using
End Using
然後我裝我的XAML格式文本框與存儲流作爲DataFormats.Rtf。
RichTextBox1.SelectAll()
RichTextBox1.Selection.Load(ClassName.RTFDataProperty, DataFormats.Rtf)
這給了我一個格式和佈局該文件的模板。 (更多案例情景,而不是通常的做法)
我也想申請一個開始選擇所以這裏是我做的有:
'--Get my RichTextBox Text
rtbtext As String = New TextRange(RichTextBox1.Document.contentStart, RichTextbox1.Document.ContentEnd).Text
Dim strStartSelection As String = "Comments..."
Dim startTP As TextPointer
Dim endTP As TextPointer
'--Loop through the paragraphs of the richtextbox for my needed selection starting point:
For Each para As Paragraph In RichTextBox1.Document.Blocks
Dim paraText As String = New TextRange(para.ContentStart, para.ContentEnd).Text
If paraText = "" Then
Dim pos As TextPointer = para.ContentStart
startTP = pos
endTP = startTP.GetPositionAtOffset("".Length + 3) '--my string had ... on the end so had to add for avoiding the escape of that on length
RichTextBox1.Selection.Select(startTP, endTP)
RichTextBox1.Focus()
Exit For
End If
Next
這是一個簡單的VB.net代碼佈局,但如果你覺得它有用,你可以從那裏簡化和調整。
由於
上述建議將不起作用作爲XamlReader.Load需要流,XamlReader,或XmlReader中未分配的。 –