Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Tue Nov 07, 2017 10:49 am

Hello,
I have a question regarding the XLS-reading of an Excel-File, using the RichText.RtfText property.

When I read an Excel-cell like:
Code: Select all
Spire.Xls.Workbook wb = new Spire.Xls.Workbook();
wb.LoadFromFile(path);
wb.ActiveSheetIndex = 0;
Spire.Xls.Worksheet ws = wb.Worksheets[0];
Spire.Xls.CellRange rng = ws.Range[idx, 4];


and then using the RichText property to retrieve the formatted entry of this cell:
Code: Select all
if (rng.HasRichText)
    RTF = rng.RichText.RtfText;


I suppose, that I have the RTF-formatted string within 'RTF'.

Now I'm loading this 'RTF' into a RichTextBox (via Windows, .net 4.5.2, WPF-RichTextBox):
Code: Select all
MemoryStream stream = new MemoryStream(Encoding.Default.GetBytes(RTF));
FlowDocument fd = new FlowDocument();
TextRange targetRange = new TextRange(fd.ContentStart, fd.ContentEnd);
targetRange.Load(stream, DataFormats.Rtf);
rtb_text.Document = fd;


But then, within the RichTextBox, the entry is displayed without any LineBreaks!

I tried to manipulate the Range-Text before using the rng.RichText.RtfText-Getter (replacing \n by \r\n and stuff like this). But then, the rng.hasRichText attribute is always false (and RichText is kind'a lost).

Can anybody tell me, what I'm doing wrong?
I need to show the entries of an Excel-Cell with all present formatting within a WPF-RichTextBox.

Thanks in advance

MaSchr
 
Posts: 2
Joined: Tue Nov 07, 2017 10:29 am

Wed Nov 08, 2017 10:05 am

Hello,

Thanks for your inquiry. I have noticed the issue and posted it to our DEV team for further investigation. If there is any update, we will let you know.

Best regards,
Simon
E-iceblue support team
User avatar

Simon.yang
 
Posts: 620
Joined: Wed Jan 11, 2017 2:03 am

Wed Nov 08, 2017 11:44 am

I discovered (after some trial and error), that replacing the RTF-codes

Code: Select all
  \u10*  by  \line


will fix the correct display of the linebreaks, but up until now I don't know how to handle the correct display of the paragraphs...

MaSchr
 
Posts: 2
Joined: Tue Nov 07, 2017 10:29 am

Thu Nov 09, 2017 2:12 am

Hello,

Thanks for your sharing. I will post the information to our DEV team and keep you informed about the progress.

Best regards,
Simon
E-iceblue support team
User avatar

Simon.yang
 
Posts: 620
Joined: Wed Jan 11, 2017 2:03 am

Wed Nov 15, 2017 6:18 am

Hello,

With further investigation, we find that the issue can't be fixed, because the WPF-RichTextBox can't recognize the "\u10*" as line break. But you could replace all the "\u10*" with "\line" to display the RTF correctly in a WPF-RichTextBox. Hope it helps.
Code: Select all
RTF = rng.RichText.RtfText.Replace(@"\u10*", @"\line");


Best regards,
Simon
E-iceblue support team
User avatar

Simon.yang
 
Posts: 620
Joined: Wed Jan 11, 2017 2:03 am

Fri Nov 17, 2017 9:44 am

Hello,

Greeting from E-iceblue.
How is the issue going? Is the solution helpful?
Your feedback will be greatly appreciated.

Sincerely,
Simon
E-iceblue support team
User avatar

Simon.yang
 
Posts: 620
Joined: Wed Jan 11, 2017 2:03 am

Return to Spire.XLS

cron