This project has moved and is read-only. For the latest updates, please go here.

reading rich text

Jun 20, 2011 at 11:43 PM
Edited Jun 20, 2011 at 11:44 PM

  I"d like to read a cell value that has bold and italicized text.  I'd presume this is RichText :).  I've been having problems- I can read the text but I haven't been able to get the Bold/Italic boundaries.

  I'm using the below code to output richtext with some formatting as HTML.  What I'm seeing though is that the Cell.RichText only has one part which contains the entire text (part.Bold and part.Italic is false).  Cell.Text is an empty string.  Is there another way to do this?

(btw, nice library.  Day #1 I was importing/exporting with good results)


        string GetRichTextAsHtml(ExcelRangeBase cell)
            StringBuilder sb = new StringBuilder();

            foreach(var part in cell.RichText)
                if (part.Bold)

                if (part.Italic)


                if (part.Italic)

                if (part.Bold)

            return sb.ToString();

Jun 22, 2011 at 7:37 PM

No, this should be the way to do it. I'll have a look at it.

Jun 22, 2011 at 9:56 PM

Thanks, let me know if there are any questions.  The xlsx file was created in EPPlus, then manually edited to add bold.  I just hit ctrl+B or ctrl+I while highlighting some text in a field.  Thats all I tried though, so I don't know the repro steps need to be so specific.