0

I have some cells cached in the C# script that I want to change their font color from code to diferentiate their values, there is any way in C# to do this?

I am already using the libraries NPOI and DocumentFormat.OpenXml, but I do not find how to change the font color with them.

I want something similar to this, change the value from black to red: enter image description here

  • Have you tried a "google" search? I found this one on SO https://stackoverflow.com/questions/47267550/npoi-does-not-change-cell%c2%b4s-font-color – FrankM Jul 09 '21 at 11:53

1 Answers1

0
CellStyle style = wb.createCellStyle();
Font font = wb.createFont();
font.setColor(HSSFColor.HSSFColorPredefined.BLACK.getIndex());
style.setFont(font);

for the cached cell use above code to change the color.

  • I have a similar code and it does nothing IFont font = xssWorkbook.CreateFont(); font.Color = XSSFFont.DEFAULT_FONT_COLOR; ICellStyle defaultStyle = xssWorkbook.CreateCellStyle(); defaultStyle.SetFont(font); And below, when setting the cell color: cell.CellStyle = defaultStyle; – Enrique González Jul 12 '21 at 07:16
  • For more context, I am using this excel only to read the info inside, the font color is the only thing I want to "write" in the excel. – Enrique González Jul 12 '21 at 08:02