nas*_*ski 2 c# openxml openxml-sdk
我试图设置细胞样式,我不能让颜色正常工作,我正在使用以下填充:
// <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);
Run Code Online (Sandbox Code Playgroud)
这些是我唯一的样式,这是我唯一的填充 - 我将第一行设置为StyleIndex = 1
此外,我制作BackgroundColor或完全省略它似乎并不重要.
从以下链接:https://blogs.msdn.microsoft.com/chrisquon/2009/11/30/stylizing-your-excel-worksheets-with-open-xml-2-0/
但问题是我的细胞现在看起来像这样:
你可以看到它不是它应该是灰色的 - 任何想法我错过了什么?谢谢.
出于某种原因,我似乎无法找到记录,Fill Id 0将始终为None,而Fill Id 1将始终为Gray125.如果你想要一个自定义填充,你将需要至少填写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
Run Code Online (Sandbox Code Playgroud)