OpenXML 无法为单元格着色

OpenXML having trouble coloring cells

我正在尝试设置单元格样式,但我无法让颜色正常工作,我正在使用以下填充:

// <Fills>
Fill fill0 = new Fill();        // Default fill
Fill fill1 = new Fill(
    new PatternFill(
        new ForegroundColor() { Rgb = new HexBinaryValue() { Value = "DCDCDC" } }
    )
    { PatternType = PatternValues.Solid });

Fills fills = new Fills();      // appending fills
fills.Append(fill0);
fills.Append(fill1);

CellFormat _0_default = new CellFormat() { FontId = 0, FillId = 0, BorderId = 0 }; // Default style : Mandatory | Style ID =0
CellFormat _1_header = new CellFormat() { FontId = 1, FillId = 1, ApplyFill = true }; //HEADER

CellFormats cellformats = new CellFormats();
cellformats.Append(_0_default);
cellformats.Append(_1_header);

这些是我唯一的样式,那是我唯一的填充 - 我将第一行设置为 StyleIndex = 1

此外,我制作 BackgroundColor 的内容或完全省略它似乎并不重要。

来自这个link:https://blogs.msdn.microsoft.com/chrisquon/2009/11/30/stylizing-your-excel-worksheets-with-open-xml-2-0/

但问题是我的细胞现在看起来像这样:

您看到的不是应该的灰色 - 知道我错过了什么吗?谢谢。

出于某种原因,我似乎找不到记录,填充 ID 0 将始终为 None,填充 ID 1 将始终为 Gray125。如果您想要自定义填充,您至少需要达到 Fill Id 2。如果对此有任何进一步的解释,我们将不胜感激!

            // <Fills>
        Fill fill1 = new Fill(
            new PatternFill(
                new ForegroundColor() { Rgb = new HexBinaryValue() { Value = "DCDCDC" } }
            )
            { PatternType = PatternValues.Solid });

        Fills fills = new Fills(
            new Fill(new PatternFill() { PatternType = PatternValues.None }), //this is what it will be REGARDLESS of what you set it to
            new Fill(new PatternFill() { PatternType = PatternValues.Gray125 }), //this is what it will be REGARDLESS of what you set it to
            fill1);

        // <Borders>
        Border border0 = new Border();     // Default border

        Borders borders = new Borders();    // <APPENDING Borders>
        borders.Append(border0);

        CellFormat _0_default = new CellFormat() { FontId = 0, FillId = 0, BorderId = 0 }; // Default style : Mandatory | Style ID =0
        CellFormat _1_header = new CellFormat() { FontId = 1, FillId = 2, ApplyFill = true }; //HEADER