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