I am attempting to style cells and I cant get the colors to work correctly, I am using the following Fill:
// <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);
These are my only styles, and that is my only fill - I set the first row to StyleIndex = 1
Also, it doesn't seem to matter what I make the BackgroundColor or if I omit it completely.
From this link: https://blogs.msdn.microsoft.com/chrisquon/2009/11/30/stylizing-your-excel-worksheets-with-open-xml-2-0/
But the problem is that my cells now look like this:
Which you can see is not the gray that it should be - any idea what I am missing? Thank you.
For some reason I cannot seem to find documented, Fill Id 0 will always be None, and Fill Id 1 will always be Gray125. If you want a custom fill, you will need to get to at least Fill Id 2. Any further explanation to this would be greatly appreciated!
// <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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With