Cell styles in OpenXML spreadsheet (SpreadsheetML)

前端 未结 2 480
梦毁少年i
梦毁少年i 2020-12-01 01:01

I\'ve generated a .xlsx spreadsheet in C# using the OpenXML SDK, but can\'t figure out how to get cell styles working. I\'ve been studying files produced by Excel, and can\'

2条回答
  •  盖世英雄少女心
    2020-12-01 01:23

    A more generic answer, all this I found after testing, so no documentation to point to.

    Once you set a CellFormats collection in the stylesheet Excel runs a deeper validation on it.

    CellFormats cannot be empty, it must have at least one CellFormat there.

    Once you add a CellFormat, Excel will complain if Fills, Fonts or Borders collections are empty.

    First Font is used as default for whole workbook and also Column/Row headers in Excel.

    Excel will ignore first CellFormat, so just add an empty one.

    If you need a Border or Fill in your format, Excel will also ignore first Border and Fill, so also add empty ones as first child in Borders and Fills.

    Finally, starting in the second CellFormat (s = "1") you're good to go.

    Tested in Excel 2010.

提交回复
热议问题