使用 rtf 加载数据仅对以下数据进行例外

本文关键字:数据 rtf 加载 使用 | 更新日期: 2024-10-30 14:40:04

使用此代码在 qpf 中加载数据时

public static void LoadRTF(string rtf, RichTextBox richTextBox)
    {
        if (string.IsNullOrEmpty(rtf))
        {
            throw new ArgumentNullException();
        }
        TextRange textRange = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);
        //Create a MemoryStream of the Rtf content
        using (MemoryStream rtfMemoryStream = new MemoryStream())
        {
            using (StreamWriter rtfStreamWriter = new StreamWriter(rtfMemoryStream))
            {
                rtfStreamWriter.Write(rtf);
                rtfStreamWriter.Flush();
                rtfMemoryStream.Seek(0, SeekOrigin.Begin);
                //Load the MemoryStream into TextRange ranging from start to end of RichTextBox.
                try
                {
                    textRange.Load(rtfMemoryStream, DataFormats.Rtf);
                }
                catch { Exception ex; }
            }
        }
    }

应用程序引发一个名为

数据格式"富文本格式"中无法识别的结构。''r'参数名称:流

数据是

<span dir="LTR" style="font-size: 9pt; background: none repeat scroll 0% 0% transparent; font-family: &quot;verdana&quot;,&quot;sans-serif&quot;; color: #444444;">Abu Dhabi Retirement Pensions &amp; Benefits Fund has announced that the Fund has fully enabled 37 electronic services provided via its online portal that was launched on June 2012. This is an indication of the Fund&rsquo;s concern to convoy Abu Dhabi&rsquo;s Government Vision and the Fund&rsquo;s strategy. There are 17 services which are allocated for entities. 775 governmental, semi-governmental and private entities are using these services and 2716 transactions have been accomplished last July. 13 other electronic services were categorized as general services targeted the active members, pensioners, and entities in which these services were used 2056 times since they were launched.&nbsp;</span><span dir="LTR" style="font-size: 9pt; font-family: &quot;verdana&quot;,&quot;sans-serif&quot;; color: #444444;"><br /> <span style="background: none repeat scroll 0% 0% transparent;">Moreover, there are seven electronic services presented to the partners from governmental and semi-governmental entities in order to ease the exchanging of information and transactions among the entities and the Fund and to support Abu Dhabi&rsquo;s government strategy to develop services.&nbsp;</span><br /> <span style="background: none repeat scroll 0% 0% transparent;">12 electronic services are expected to be launched for pensioners and beneficiaries and active members in 2014 which will enhance the level of the provided services.</span></span> 

这是RTF格式是什么错误{''RTF1''ANSI''ANSICPG1252''UC1''HTMAUTSP''deff2{''fonttbl{''f0''fcharset0 Times New Roman;}{''f2''fcharset0 Segoe UI;}{''f3''fcharset0 verdana";}}{''colortbl''red0''green0''blue0;''red255''green255''blue255;''red68''green68''blue68;}''loch''hich''dbch''pard''plain''ltrpar''itap0{''lang1033''fs18''f2''cf0 ''cf0''ql{''f2 {''loch''f3''cf2''ltrch 阿布扎比退休养老金和福利基金宣布,该基金已全面启用通过其在线门户提供的37项电子服务,该门户网站于2012年6月推出。这表明基金''rquote关注阿布扎比的政府愿景和基金的战略''rquote。有17项服务分配给实体。775个政府、半政府和私营实体正在使用这些服务,去年7月完成了2 716笔交易。其他13项电子服务被归类为一般服务,针对活跃成员,养老金领取者和实体,自推出以来使用这些服务2056次。}''line {''loch''f3''cf2''ltrch 此外,政府和半政府实体向合作伙伴提供了七项电子服务,以便利实体和基金之间的信息和交易交流,并支持阿布扎比''rquote政府发展服务的战略。 预计2014年将为养恤金领取者、受益人和在职成员推出12号线电子服务,这将提高所提供服务的水平。}''li0''ri0''sa0''sb0''fi0''ql''par}}}

使用 rtf 加载数据仅对以下数据进行例外

span不是

RTF标签,而是html,因此出现"无法识别的结构"异常消息

尝试改用标签,或者首先将 HTML 源代码放入 HTML> RTF 转换器。

编辑:

好的,所以 Span 不是一个有效的 rtf 标签,但它是一个有效的 WPF 类,可以很好地进入流文档,所以我想它可以在这种情况下工作。

不过,您的代码存在一个问题:SPAN 类似乎没有任何"dir"属性 http://msdn.microsoft.com/en-us/library/system.windows.documents.span%28v=vs.110%29.aspx:

所以我建议删除 dir="ltr"(如果我没记错的话,在这种情况下无论如何都是无用的)