ClosedXML: Cannot Set Header FontColor Of Table To Black

Do you want to request a feature or report a bug?

  • Bug

Version of ClosedXML

0.91.0

What is the current behavior?

I have some data which are displayed as a standard table. If I want to set the FontColor of the Table’s Header to Black the FontColor is still white. If I set the color to almost black (#FF010101 ) or some other color (e.g. XLColor.Red) it works as expected.

What is the expected behavior or new feature?

The FontColor of the Table’s Header should be black.

Did this work in previous versions of our tool? Which versions?

No

Reproducibility

Code to reproduce problem:

class Data
{
  public int Property1 { get; set; }
  public int Property2 { get; set; }
  public int Property3 { get; set; }
  public int Property4 { get; set; }
  public int Property5 { get; set; }
}

class Program
{
  static List<Data> GenerateData()
  {
    List<Data> list = new List<Data>();
    Random r = new Random();
    for (int i = 0; i < 15; i++)
    {
      list.Add(new Data { Property1 = r.Next(0, 100), Property2 = r.Next(0, 100), Property3 = r.Next(0, 100), Property4 = r.Next(0, 100), Property5 = r.Next(0, 100) });
    }
    return list;
  }

  static void Main(string[] args)
  {
    var data = GenerateData();
    var typeAccessor = TypeAccessor.Create(typeof(Data));
    var path = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "test.xlsx");

    using (var workbook = new XLWorkbook(XLEventTracking.Disabled))
    {
      using (var sheet = workbook.AddWorksheet("test"))
      {
        int row = 1;
        int column = 1;

        foreach (var member in typeAccessor.GetMembers())
        {
          sheet.Cell(row, column++).Value = member.Name;
        }
        row++;

        foreach (var item in data)
        {
          column = 1;
          foreach (var member in typeAccessor.GetMembers())
          {
            sheet.Cell(row, column++).Value = typeAccessor[item, member.Name];
          }
          row++;
        }

        using (var table = sheet.Range(1, 1, row - 1, column - 1).CreateTable())
        {
          using (var rangeRow = table.HeadersRow())
          {
            rangeRow.Style.Font.FontColor = XLColor.Black;  // doesn't work
            rangeRow.Style.Font.FontColor = XLColor.FromHtml("#FF010101");  // works
            rangeRow.Style.Fill.BackgroundColor = XLColor.NoColor;
          }
        }
      }
      workbook.SaveAs(path);
    }
  }
}

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 15 (9 by maintainers)

Most upvoted comments

Yes, it’s not a bug in ClosedXML.

You could try rangeRow.Style.Font.FontColor = XLColor.FromTheme(XLThemeColor.Text1);.

Ah, but if I change it to XLColor.Black, I see this. This is obviously wrong. I’ll look into it.

image

If I open test.xlsx I see this: image