public static uint GetOrSetErrorFillID(SpreadsheetDocument workdocument) { WorkbookStylesPart stylesPart = workdocument.WorkbookPart.WorkbookStylesPart; Fills fills = stylesPart.Stylesheet.Fills; Fill cellFill = null; uint fillId = 0; if (!ExistsRedFillPattern(fills, ref cellFill, ref fillId)) { Fill newErrorFill = new Fill(); PatternFill newErrorPattern = new PatternFill() { PatternType = PatternValues.Solid }; newErrorPattern.AppendChild(new ForegroundColor() { Rgb = "FFFF0000" }); newErrorPattern.AppendChild(new BackgroundColor() { Indexed = 64 }); newErrorFill.AppendChild(newErrorPattern); fills.AppendChild(newErrorFill); fills.Count++; } workdocument.Save(); ErrorStyleFillId = fillId; return(fillId); }
private static Fills AddFills() { Fills fills1 = new Fills() { Count = 5U }; // FillId = 0 Fill fill1 = new Fill(); PatternFill patternFill1 = new PatternFill() { PatternType = PatternValues.None }; fill1.AppendChild(patternFill1); // FillId = 1 Fill fill2 = new Fill(); PatternFill patternFill2 = new PatternFill() { PatternType = PatternValues.Gray125 }; fill2.AppendChild(patternFill2); // FillId = 2,ORANGE Fill fill3 = new Fill(); PatternFill patternFill3 = new PatternFill() { PatternType = PatternValues.Solid }; ForegroundColor foregroundColor1 = new ForegroundColor() { Rgb = "FFED7D31" }; BackgroundColor backgroundColor1 = new BackgroundColor() { Indexed = 64U }; patternFill3.AppendChild(foregroundColor1); patternFill3.AppendChild(backgroundColor1); fill3.AppendChild(patternFill3); // FillId = 3,BLUE Fill fill4 = new Fill(); PatternFill patternFill4 = new PatternFill() { PatternType = PatternValues.Solid }; ForegroundColor foregroundColor2 = new ForegroundColor() { Rgb = "FF4472C4" }; BackgroundColor backgroundColor2 = new BackgroundColor() { Indexed = 64U }; patternFill4.AppendChild(foregroundColor2); patternFill4.AppendChild(backgroundColor2); fill4.AppendChild(patternFill4); // FillId = 4,YELLO Fill fill5 = new Fill(); PatternFill patternFill5 = new PatternFill() { PatternType = PatternValues.Solid }; ForegroundColor foregroundColor3 = new ForegroundColor() { Rgb = "FFFFFF00" }; BackgroundColor backgroundColor3 = new BackgroundColor() { Indexed = 64U }; patternFill5.AppendChild(foregroundColor3); patternFill5.AppendChild(backgroundColor3); fill5.AppendChild(patternFill5); fills1.AppendChild(fill1); fills1.AppendChild(fill2); fills1.AppendChild(fill3); fills1.AppendChild(fill4); fills1.AppendChild(fill5); //fills1.AppendChild(fill6); return(fills1); }