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

Jun 16, 2011 at 7:25 PM
Edited Jun 16, 2011 at 7: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                      
Coordinator
Jun 16, 2011 at 7:32 PM

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

Coordinator
Jun 23, 2011 at 5: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("Hello").SetFontColor(XLColor.Red);
            cell.RichText.AddText(" BIG ").SetFontColor(XLColor.Blue).SetBold();
            cell.RichText.AddText("World").SetFontColor(XLColor.Red);

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)
                    Console.WriteLine(richString.Text);
            }

Jun 23, 2011 at 4:30 PM

You, sir, are amazing!

Thank you and keep up the great work.

Jan 17, 2012 at 3:00 AM

Has rich text been implemented ?

Coordinator
Jan 17, 2012 at 3:01 AM

Is that a trick question?

Jan 17, 2012 at 3: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.

Coordinator
Jan 17, 2012 at 4:25 AM

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