清理 RTF 文本 [英] Cleaning up RTF text
问题描述
我想获取一些 RTF 输入并清理它以删除除 ul i 之外的所有 RTF 格式,以便将其粘贴到带有次要格式信息的 Word 中.
I'd like to take some RTF input and clean it to remove all RTF formatting except ul i to paste it into Word with minor format information.
用于粘贴到 Word 中的命令类似于:oWord.ActiveDocument.ActiveWindow.Selection.PasteAndFormat(0)(剪贴板中已有一些 RTF 文本)
The command used to paste into Word will be something like: oWord.ActiveDocument.ActiveWindow.Selection.PasteAndFormat(0) (with some RTF text already in the Clipboard)
{
tf1ansideff0{fonttbl{f0fnilfcharset0 Courier New;}}
{colortbl ;
ed255green255lue140;}
viewkind4uc1pardhighlight1lang3084f0fs18 The company is a global leader in responsible tourism and was ul the first major hotel chain in North Americaulnone to embrace environmental stewardship within its daily operationshighlight0par
你知道如何使用正则表达式或其他东西安全地清理 RTF 吗?我正在使用 VB.NET 进行处理,但任何 .NET 语言示例都可以.
Do you have any idea on how I can clean up the RTF safely with some regular expressions or something? I am using VB.NET to do the processing but any .NET language sample will do.
推荐答案
我会使用一个隐藏的 RichTextBox,设置 Rtf 成员,然后检索 Text 成员,以一种受支持的方式清理 RTF.然后我会在之后手动注入所需的格式.
I would use a hidden RichTextBox, set the Rtf member, then retrieve the Text member to sanitize the RTF in a well-supported way. Then I would use manually inject the desired formatting afterwards.
这篇关于清理 RTF 文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!