2013-12-18 16 views
1

使用此代碼在QPF負荷信息與RTF進行異常有以下數據僅

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; } 
      } 
     } 
    } 

加載數據的應用程序提高叫

數據形式

無法識別的結構「RTF格式異常時」 \ r \ n參數名:流

數據是

<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福利基金已宣佈,該基金已全面啓用37項電子服務,該服務是通過其於6月份推出的在線門戶網站提供的37項電子服務這反映了基金組織對阿布扎比政府願景和基金組織戰略的關注。有17個服務是爲實體分配的。 775個政府,半政府和私營機構正在使用這些服務,去年7月已完成2716項交易。其他13種電子服務被列爲一般服務,針對活躍成員,養老金領取者和實體,這些服務自推出以來已被使用2056次。 } \ line {\ loch \ f3 \ cf2 \ ltrch此外,政府和半政府實體向合作伙伴提供了七項電子服務,以減輕實體和基金間信息和交易的交流,並支持阿布阿布扎比政府制定服務戰略。 \ line 12電子服務預計將於2014年爲退休人員和受益人及活躍會員推出,這將提高所提供服務的水平。} \ li0 \ ri0 \ sa0 \ sb0 \ fi0 \ ql \ par} } }

+0

在什麼線? – 2013-12-18 06:57:40

+0

textRange.Load(rtfMemoryStream,DataFormats.Rtf); –

+0

原因是因爲數據不是RTF,它的HTML。它找不到RTF樣式標籤。 – paqogomez

回答

1

跨度是不是一個RTF標籤,它的HTML,因此「無法識別的結構」異常消息

嘗試使用標籤來替代,或者把你的HTML源第一槽一個html> RTF轉換。

編輯:

好了,所以跨度是不是有效的RTF標籤,但它是一個有效的WPF類,即順利進入FlowDocument的,所以我想它可以在這種情況下工作。

有一個問題與您的代碼,但:跨度類似乎沒有任何「目錄」屬性:http://msdn.microsoft.com/en-us/library/system.windows.documents.span%28v=vs.110%29.aspx

所以我建議去掉DIR =「升」(這是在這種情況下無用無論如何,如果我沒有弄錯)

+0

但我已經有另一行數據,包括跨度,它工作正常 –