How to use different colors of texts in same Excel cell using ClosedXML?
Asked Answered
B

1

8

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.

Bradfordbradlee answered 21/9, 2016 at 12:16 Comment(2)
try worksheet.Cell(1, 1).Style.Font.FontColorCrusty
Thanks but I tried the same,this will apply the color to whole cell text.I need portion of the text to be colored.@CrustyBradfordbradlee
B
16

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.

Buggy answered 21/9, 2016 at 13:2 Comment(4)
*worksheet.Cell(1,1).RichText.Substring(StartIndex, NoOfChar).SetFontColor(XLColor.Red);Crusty
@Raidri, you seem to know the library well. We could use your help in developing it further. github.com/Closedxml/ClosedxmlGalicia
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?)Sternlight
Instead of Cell(1,1).RichtText use Cell(1,1).GetRichText()Baxley

© 2022 - 2024 — McMap. All rights reserved.