C# OpenXML无法为单元格着色
我正在尝试设置单元格样式,但无法正确使用颜色,我正在使用以下填充:C# OpenXML无法为单元格着色,c#,openxml,openxml-sdk,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 =
// <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);
//
填充0=新填充();//默认填充
填充1=新填充(
新图案填充(
new ForegroundColor(){Rgb=new HexBinaryValue(){Value=“DCDC”}
)
{PatternType=PatternValues.Solid});
填充=新填充();//附加填充
fills.Append(fill0);
fills.Append(fill1);
CellFormat\u 0\u默认值=新CellFormat(){FontId=0,FillId=0,BorderId=0};//默认样式:必填|样式ID=0
CellFormat 1_header=newCellFormat(){FontId=1,FillId=1,ApplyFill=true}//标题
CellFormats CellFormats=新的CellFormats();
cellformats.Append(\u 0\u默认值);
附加(_1_头);
这些是我唯一的样式,这是我唯一的填充-我将第一行设置为StyleIndex=1
而且,我制作背景色或者是否完全省略背景色似乎并不重要
通过此链接:
但问题是我的细胞现在看起来像这样:
你能看到的不是应该是灰色的——你知道我错过了什么吗?谢谢。由于某些原因,我似乎找不到文档,填充Id 0将始终为无,填充Id 1将始终为灰色。如果您想要自定义填充,则至少需要获得填充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
//
填充1=新填充(
新图案填充(
new ForegroundColor(){Rgb=new HexBinaryValue(){Value=“DCDC”}
)
{PatternType=PatternValues.Solid});
填充=新填充(
new Fill(new PatternFill(){PatternType=PatternValues.None}),//不管您将其设置为什么,它都是这样的
new Fill(new PatternFill(){PatternType=PatternValues.Gray125}),//不管您将其设置为什么,它都是这样的
填充1);
//
边框边框0=新边框();//默认边框
Borders Borders=新边框();//
borders.Append(border0);
CellFormat\u 0\u默认值=新CellFormat(){FontId=0,FillId=0,BorderId=0};//默认样式:必填|样式ID=0
CellFormat 1_header=newCellFormat(){FontId=1,FillId=2,ApplyFill=true}//标题
我认为在你的值中,FFFFFF 00是一个错误,RGB颜色只使用了六个字符,你的输入似乎是RGBA值。更新以反映这一点-似乎没有改变任何东西。只是为了掩盖明显的问题:你是在用单元格填充吗?我认为@RayFischer是正确的,您看到的填充看起来可疑地像PatternValues.Gray125
。您能在使用填充的地方显示代码吗?如果非要我猜的话,我会说你的FillId
。好吧。。。因此,Fillid0始终是透明的,而Fillid1始终是灰色的,因此您需要手动添加这些填充,然后添加自定义填充。对我来说也没什么意义。我也有同样的问题!谢谢你的帖子。同样的问题!谢谢。对于对此感兴趣的任何人,ISO/IEC 29500 2.1.704第1部分第18.8.21节中记录了这一点:“b.本标准允许这些元素的任意定义:在Excel中,保留前两个填充(“ISO/IEC-29500-1]§18.8.20;填充”)值,并且不考虑其预定义值的偏差。”