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

[Feature Request] Ability to apply different colors to characters in a cell

Jun 16, 2011 at 8:25 PM
Edited Jun 16, 2011 at 8:25 PM

If this feature already exists in ClosedXML, then I was unable to find it.  :)

It would be great if we could apply different colors to characters within a cell. Something like this:

      some text                      
Jun 16, 2011 at 8:32 PM

I'm working on rich text right now...

Jun 23, 2011 at 6:07 AM

Rich text functionality has been added. I'll release it once I implement phonetic properties. You'll be able to add text like this:

            cell.RichText.AddText(" BIG ").SetFontColor(XLColor.Blue).SetBold();

Hello BIG World

One feature I'm particularly proud of is that you can modify the rich text like it's just a single string:

            cell.RichText.Substring(3, 8).SetUnderline();
Hello BIG World

cell.RichText.Text and cell.RichText.ToString() will return "Hello BIG World".
And of course you can loop through each text block in the rich text:

            Console.WriteLine("The following pieces of text are in bold:");
            foreach (var richString in cell.RichText)
                if (richString.Bold)

Jun 23, 2011 at 5:30 PM

You, sir, are amazing!

Thank you and keep up the great work.

Jan 17, 2012 at 4:00 AM

Has rich text been implemented ?

Jan 17, 2012 at 4:01 AM

Is that a trick question?

Jan 17, 2012 at 4:51 AM

no - not a trick question - above you said " I'll release it once I implement phonetic properties". Was just wondering if it has been released.

I did a search of the xml file that is in the current download to see if there was any mention of RichText - but nothing came up. Is RichText implemented in the current release (and maybe not documented in the xml) ? I need to set colors to substrings as you demonstrate above.

Jan 17, 2012 at 5:25 AM

Yes it has, look for rich text under the styles section of the documentation page...