7

How to use different colors of texts in the same Excel cell using ClosedXML?

worksheet.Cell(1,1).Value.Character[StartIndex, NoOfChar].Font.Color....??

ClosedXML doesn't have something like above, please help me to use two different font colors in the same cell.

Raidri
  • 17,258
  • 9
  • 62
  • 65
WSk
  • 183
  • 4
  • 16

1 Answers1

14

Use RichText to style different parts of the cell, for example:

worksheet.Cell(1,1).RichText.Substring(StartIndex, NoOfChar).SetFontColor(XLColor.Red);

See the documentation for more details.

Raidri
  • 17,258
  • 9
  • 62
  • 65
  • 2
    *worksheet.Cell(1,1).RichText.Substring(StartIndex, NoOfChar).SetFontColor(XLColor.Red); – Innat3 Sep 21 '16 at 13:08
  • @Raidri, you seem to know the library well. We could use your help in developing it further. http://github.com/Closedxml/Closedxml – Francois Botha Sep 22 '16 at 05:03
  • strangely, i get this error. Is RichText deprecated in ClosedXML? CS1061: "XLCell" does not contain a definition for 'RichText' and no accessible extension method 'Rich Text accepting a first argument of type 'IXLCell' could be found (are you missing a using directive or an assembly reference?) – user3267567 Aug 03 '23 at 05:57