public static Fills GenerateFills() { Fills fills1 = new Fills() { Count = (UInt32Value)2U }; Fill fill1 = new Fill(); PatternFill patternFill1 = new PatternFill() { PatternType = PatternValues.None }; fill1.Append(patternFill1); Fill fill2 = new Fill(); PatternFill patternFill2 = new PatternFill() { PatternType = PatternValues.Gray125 }; fill2.Append(patternFill2); fills1.Append(fill1); fills1.Append(fill2); return(fills1); }
public static Fills GenerateFills() { Fills fills1 = new Fills() { Count = (UInt32Value)3U }; Fill fill1 = new Fill(); PatternFill patternFill1 = new PatternFill() { PatternType = PatternValues.None }; fill1.Append(patternFill1); Fill fill2 = new Fill(); PatternFill patternFill2 = new PatternFill() { PatternType = PatternValues.Gray125 }; fill2.Append(patternFill2); Fill fill3 = new Fill(); PatternFill patternFill3 = new PatternFill() { PatternType = PatternValues.Solid }; ForegroundColor foregroundColor1 = new ForegroundColor() /*Theme = (UInt32Value)0U, Tint = -0.14999847407452621D*/ Rgb {
/// <summary> /// <see cref="IMCItem"/> の色情報を使用して、<see cref="Fill"/> を生成します。 /// </summary> /// <param name="item"></param> /// <returns></returns> private Fill _createFillFromMCItem(IMCItem item) { // "#RRGGBB" => "FFRRGGBB" var backgroundColorCode = HexBinaryValue.FromString(this._mcItemToArgbCode(item)); var pFill = new PatternFill() { PatternType = PatternValues.Solid }; pFill.Append(new ForegroundColor() { Rgb = backgroundColorCode }); pFill.Append(new BackgroundColor() { Rgb = backgroundColorCode }); var fill = new Fill(); fill.Append(pFill); return(fill); }
private void InitialFillStyleSheet() { #region Fill None (ID: 0) Fill fill = new Fill(); fill.Append(new PatternFill() { PatternType = PatternValues.None }); this.SetStyle <Fill>(fill); #endregion #region Fill None (ID: 0) Fill fillG = new Fill(); fillG.Append(new PatternFill() { PatternType = PatternValues.Gray125 }); this.SetStyle <Fill>(fillG); #endregion }
public int SetConditionStyle(string fontName = DefaultFont, double fontSize = 10D, bool fontBold = false, string fontColor = null, string fill = null) { DifferentialFormat format = new DifferentialFormat(); Font font = new Font(); font.Append(new FontName() { Val = fontName }); font.Append(new FontSize() { Val = fontSize }); if (fontColor == null) { font.Append(new Color() { Theme = (UInt32Value)1U }); } else { font.Append(new Color() { Rgb = fontColor }); } if (fontBold) { font.Append(new Bold()); } format.Append(font); if (fill != null) { Fill f = new Fill(); PatternFill p = new PatternFill() { PatternType = PatternValues.Solid }; p.Append(new ForegroundColor() { Rgb = fill }); p.Append(new BackgroundColor() { Rgb = fill }); f.Append(p); format.Append(f); } return(this.SetStyle <DifferentialFormat>(format)); }
private UInt32Value SetCellStyle(System.Drawing.Color fillColor, bool locked) { Fill fill = new Fill(); PatternFill patternFill = new PatternFill() { PatternType = PatternValues.Solid }; ForegroundColor foregroundColor1 = new ForegroundColor() { Rgb = System.Drawing.Color.FromArgb(fillColor.A, fillColor.R, fillColor.G, fillColor.B).Name }; BackgroundColor backgroundColor1 = new BackgroundColor() { Indexed = (UInt32Value)64U }; patternFill.Append(foregroundColor1); patternFill.Append(backgroundColor1); fill.Append(patternFill); ExcelStyleSheet.Fills.Count++; ExcelStyleSheet.Fills.Append(fill); CellFormat myCellFormat = new CellFormat { FontId = (UInt32Value)0U, FillId = (UInt32Value)ExcelStyleSheet.Fills.Count - 1, ApplyFill = true, NumberFormatId = (UInt32Value)0U, FormatId = (UInt32Value)0U, BorderId = (UInt32Value)1U, ApplyBorder = true, ApplyProtection = true }; Alignment alignment = new Alignment() { WrapText = true }; myCellFormat.Append(alignment); if (!locked) { Protection protection = new Protection() { Locked = false }; myCellFormat.Append(protection); } ExcelStyleSheet.CellFormats.Count++; ExcelStyleSheet.CellFormats.Append(myCellFormat); return((UInt32Value)ExcelStyleSheet.CellFormats.Count - 1); }
/// <summary> /// Генерировать наполнение /// </summary> /// <returns></returns> public Fill GenerateFill() { Fill fill = new Fill(); PatternFill patternFill = new PatternFill() { PatternType = PatternValues.None }; fill.Append(patternFill); return(fill); }
private static Fill Fill1() { // ReSharper disable PossiblyMistakenUseOfParamsMethod var fill1 = new Fill(); var patternFill1 = new PatternFill { PatternType = PatternValues.Gray125 }; fill1.Append(patternFill1); // ReSharper restore PossiblyMistakenUseOfParamsMethod return(fill1); }
private void AppendDefaultFills(Stylesheet stylesheet) { Fills fills = new Fills() { Count = (UInt32Value)1U }; Fill fillNone = new Fill(); PatternFill patternFillNone = new PatternFill() { PatternType = PatternValues.None }; fillNone.Append(patternFillNone); fills.Append(fillNone); stylesheet.Append(fills); }
static Fills GenerateFills() { var fills = new Fills { Count = 3U }; var fill1 = new Fill(); var patternFill1 = new PatternFill { PatternType = PatternValues.None }; fill1.Append(patternFill1); var fill2 = new Fill(); var patternFill2 = new PatternFill() { PatternType = PatternValues.Gray125 }; fill2.Append(patternFill2); var fill3 = new Fill(); var patternFill3 = new PatternFill() { PatternType = PatternValues.Solid }; var foregroundColor1 = new ForegroundColor() { Theme = (UInt32Value)0U, Tint = -0.14999847407452621D }; var backgroundColor1 = new BackgroundColor() { Indexed = (UInt32Value)64U }; patternFill3.Append(foregroundColor1); patternFill3.Append(backgroundColor1); fill3.Append(patternFill3); fills.Append(fill1); fills.Append(fill2); fills.Append(fill3); return(fills); }
public void AddFill(string name, string color, string c) { var filepath = getOutputDir() + name; using (SpreadsheetDocument spreadSheet = SpreadsheetDocument.Open(filepath, true)) { var iter = spreadSheet.WorkbookPart.WorksheetParts.GetEnumerator(); iter.MoveNext(); var workSheetPart = iter.Current; Cell cell = InsertCellInWorksheet(GetColumnName(c), GetRowIndex(c), workSheetPart); Fills fs = spreadSheet.WorkbookPart.WorkbookStylesPart.Stylesheet.Fills; var cf = spreadSheet.WorkbookPart.WorkbookStylesPart.Stylesheet.CellFormats; Fill fill1 = new Fill(); PatternFill patternFill1 = new PatternFill() { PatternType = PatternValues.Solid }; ForegroundColor foregroundColor1 = new ForegroundColor() { Rgb = color }; BackgroundColor backgroundColor1 = new BackgroundColor() { Indexed = (UInt32Value)64U }; patternFill1.Append(foregroundColor1); patternFill1.Append(backgroundColor1); fill1.Append(patternFill1); fs.Append(fill1); CellFormat cellFormat2 = new CellFormat() { NumberFormatId = 0, FontId = 0, FillId = (UInt32)(fs.Elements <Fill>().Count() - 1), BorderId = 0, FormatId = 0, ApplyFill = true }; cf.Append(cellFormat2); spreadSheet.WorkbookPart.WorkbookStylesPart.Stylesheet.Save(); cell.StyleIndex = (UInt32)(spreadSheet.WorkbookPart.WorkbookStylesPart.Stylesheet.CellFormats.Elements <CellFormat>().Count() - 1); workSheetPart.Worksheet.Save(); } }
public EWFill(System.Drawing.Color color, EWPattern pattern = EWPattern.Solid) { _oxFill = new Fill(); PatternFill patternFill3 = new PatternFill() { PatternType = pattern.As <PatternValues>() }; ForegroundColor foregroundColor1 = new ForegroundColor() { Rgb = color.ToHexString() }; //BackgroundColor backgroundColor1 = new BackgroundColor() { Indexed = (UInt32Value)64U }; patternFill3.Append(foregroundColor1); //patternFill3.Append(backgroundColor1); _oxFill.Append(patternFill3); }
public Fill ToXmlStyle() { var fill = new Fill(); var pattern = new PatternFill() { PatternType = PatternType }; if (!string.IsNullOrEmpty(FillCollor)) { pattern.ForegroundColor = new ForegroundColor() { Rgb = HexBinaryValue.FromString(FillCollor) } } ; fill.Append(pattern); return(fill); }
private void pushFillsToStylesheet(Stylesheet ss) { var fills = ss.Fills; var xn = _doc.SelectSingleNode("stylesheet/fills"); var nlst = xn.SelectNodes("fill"); Console.WriteLine(nlst.Count); foreach (XmlNode f in nlst) { var fill_id = f.Attributes.GetNamedItem("id").Value; var fill_type = f.Attributes.GetNamedItem("type").Value; Console.WriteLine(fill_type); var fill_color = f.Attributes.GetNamedItem("color").Value; Console.WriteLine(fill_color); Fill fill = new Fill(); PatternFill pf = new PatternFill() { PatternType = PatternValues.Solid }; ForegroundColor fc = new ForegroundColor() { Rgb = fill_color }; BackgroundColor bc = new BackgroundColor() { Indexed = (UInt32Value)64U }; pf.Append(fc); pf.Append(bc); fill.Append(pf); fills.Append(fill); var fill_idx = fills.Elements <Fill>().Count() - 1; fill_map.Add(fill_id, fill_idx); } }
public int SetFill(string color) { Fill fill = new Fill(); PatternFill pattern = new PatternFill() { PatternType = PatternValues.Solid }; pattern.Append(new ForegroundColor() { Rgb = color }); pattern.Append(new BackgroundColor() { Rgb = color }); fill.Append(pattern); return(this.SetStyle <Fill>(fill)); }
private static Fill Fill3() { // ReSharper disable PossiblyMistakenUseOfParamsMethod // var fill1 = new Fill(); var patternFill1 = new PatternFill { PatternType = PatternValues.Solid }; var foregroundColor1 = new ForegroundColor { Rgb = "B8CCE4" }; var backgroundColor1 = new BackgroundColor { Indexed = 64U }; patternFill1.Append(foregroundColor1); patternFill1.Append(backgroundColor1); fill1.Append(patternFill1); return(fill1); // ReSharper restore PossiblyMistakenUseOfParamsMethod }
// Generates content of workbookStylesPart1. private void GenerateWorkbookStylesPart1Content(WorkbookStylesPart workbookStylesPart1) { Stylesheet stylesheet1 = new Stylesheet(); Fonts fonts1 = new Fonts() { Count = (UInt32Value)1U, KnownFonts = true }; Font font1 = new Font(); FontSize fontSize1 = new FontSize() { Val = 11D }; Color color1 = new Color() { Theme = (UInt32Value)1U }; FontName fontName1 = new FontName() { Val = "Calibri" }; FontFamilyNumbering fontFamilyNumbering1 = new FontFamilyNumbering() { Val = 2 }; FontScheme fontScheme1 = new FontScheme() { Val = FontSchemeValues.Minor }; font1.Append(fontSize1); font1.Append(color1); font1.Append(fontName1); font1.Append(fontFamilyNumbering1); font1.Append(fontScheme1); fonts1.Append(font1); Fills fills1 = new Fills() { Count = (UInt32Value)2U }; Fill fill1 = new Fill(); PatternFill patternFill1 = new PatternFill() { PatternType = PatternValues.None }; fill1.Append(patternFill1); Fill fill2 = new Fill(); PatternFill patternFill2 = new PatternFill() { PatternType = PatternValues.Gray125 }; fill2.Append(patternFill2); fills1.Append(fill1); fills1.Append(fill2); Borders borders1 = new Borders() { Count = (UInt32Value)1U }; Border border1 = new Border(); LeftBorder leftBorder1 = new LeftBorder(); RightBorder rightBorder1 = new RightBorder(); TopBorder topBorder1 = new TopBorder(); BottomBorder bottomBorder1 = new BottomBorder(); DiagonalBorder diagonalBorder1 = new DiagonalBorder(); border1.Append(leftBorder1); border1.Append(rightBorder1); border1.Append(topBorder1); border1.Append(bottomBorder1); border1.Append(diagonalBorder1); borders1.Append(border1); CellStyleFormats cellStyleFormats1 = new CellStyleFormats() { Count = (UInt32Value)1U }; CellFormat cellFormat1 = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U }; cellStyleFormats1.Append(cellFormat1); CellFormats cellFormats1 = new CellFormats() { Count = (UInt32Value)4U }; CellFormat cellFormat2 = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U }; CellFormat cellFormat3 = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U, ApplyNumberFormat = true }; CellFormat cellFormat4 = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U, PivotButton = true }; CellFormat cellFormat5 = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U, ApplyAlignment = true }; cellFormats1.Append(cellFormat2); cellFormats1.Append(cellFormat3); cellFormats1.Append(cellFormat4); cellFormats1.Append(cellFormat5); CellStyles cellStyles1 = new CellStyles() { Count = (UInt32Value)1U }; CellStyle cellStyle1 = new CellStyle() { Name = "Normal", FormatId = (UInt32Value)0U, BuiltinId = (UInt32Value)0U }; cellStyles1.Append(cellStyle1); DifferentialFormats differentialFormats1 = new DifferentialFormats() { Count = (UInt32Value)0U }; stylesheet1.Append(fonts1); stylesheet1.Append(fills1); stylesheet1.Append(borders1); stylesheet1.Append(cellStyleFormats1); stylesheet1.Append(cellFormats1); stylesheet1.Append(cellStyles1); stylesheet1.Append(differentialFormats1); workbookStylesPart1.Stylesheet = stylesheet1; }
private uint GenerateStylesheet() { WorksheetPart worksheetPart = workbookPart.AddNewPart <WorksheetPart>(); worksheetPart.Worksheet = new Worksheet(); WorkbookStylesPart workbookStylesPart1 = workbookPart.AddNewPart <WorkbookStylesPart>(); Stylesheet stylesheet1 = new Stylesheet() { MCAttributes = new MarkupCompatibilityAttributes() { Ignorable = "x14ac x16r2 xr" } }; stylesheet1.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006"); stylesheet1.AddNamespaceDeclaration("x14ac", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac"); stylesheet1.AddNamespaceDeclaration("x16r2", "http://schemas.microsoft.com/office/spreadsheetml/2015/02/main"); stylesheet1.AddNamespaceDeclaration("xr", "http://schemas.microsoft.com/office/spreadsheetml/2014/revision"); Fonts fonts1 = new Fonts() { Count = 1U, KnownFonts = true }; Font font1 = new Font(); FontSize fontSize1 = new FontSize() { Val = 11D }; Color color1 = new Color() { Theme = 1U }; FontName fontName1 = new FontName() { Val = "Calibri" }; FontFamilyNumbering fontFamilyNumbering1 = new FontFamilyNumbering() { Val = 2 }; FontScheme fontScheme1 = new FontScheme() { Val = FontSchemeValues.Minor }; font1.Append(fontSize1); font1.Append(color1); font1.Append(fontName1); font1.Append(fontFamilyNumbering1); font1.Append(fontScheme1); fonts1.Append(font1); Fills fills1 = new Fills() { Count = 1U }; Fill fill1 = new Fill(); PatternFill patternFill1 = new PatternFill() { PatternType = PatternValues.None }; fill1.Append(patternFill1); fills1.Append(fill1); Borders borders1 = new Borders() { Count = 0U }; Border border1 = new Border(); LeftBorder leftBorder1 = new LeftBorder(); RightBorder rightBorder1 = new RightBorder(); TopBorder topBorder1 = new TopBorder(); BottomBorder bottomBorder1 = new BottomBorder(); DiagonalBorder diagonalBorder1 = new DiagonalBorder(); border1.Append(leftBorder1); border1.Append(rightBorder1); border1.Append(topBorder1); border1.Append(bottomBorder1); border1.Append(diagonalBorder1); borders1.Append(border1); CellStyleFormats cellStyleFormats1 = new CellStyleFormats() { Count = 1U }; CellFormat cellFormat1 = new CellFormat() { NumberFormatId = 0U }; cellStyleFormats1.Append(cellFormat1); CellFormats cellFormats1 = new CellFormats() { Count = 2U }; CellFormat cellFormat43 = new CellFormat() { NumberFormatId = 0U, FormatId = 0U }; CellFormat cellFormat44 = new CellFormat() { NumberFormatId = 14U, FormatId = 0U, ApplyNumberFormat = true }; cellFormats1.Append(cellFormat43); cellFormats1.Append(cellFormat44); stylesheet1.Append(fonts1); stylesheet1.Append(fills1); stylesheet1.Append(borders1); stylesheet1.Append(cellStyleFormats1); stylesheet1.Append(cellFormats1); workbookStylesPart1.Stylesheet = stylesheet1; return(1); }
// Generates content of workbookStylesPart1. private static void GenerateWorkbookStylesPartContent(WorkbookStylesPart workbookStylesPart) { Stylesheet stylesheet1 = new Stylesheet(); Fills fills1 = new Fills() { Count = (UInt32Value)3U }; Fill fill1 = new Fill(); PatternFill patternFill1 = new PatternFill() { PatternType = PatternValues.None }; fill1.Append(patternFill1); Fill fill2 = new Fill(); PatternFill patternFill2 = new PatternFill() { PatternType = PatternValues.Gray125 }; fill2.Append(patternFill2); fills1.Append(fill1); fills1.Append(fill2); Borders borders = new Borders() { Count = (UInt32Value)6U }; Border noBorder = new Border(); //id 0 borders.Append(noBorder); Border leftBorder = new Border(); //id 1 Border rightBorder = new Border(); //id 2 Border topBorder = new Border(); //id 3 Border botBorder = new Border(); //id 4 Border allBorder = new Border(); //id 5 LeftBorder leftBorder1 = new LeftBorder() { Style = BorderStyleValues.Thin }; leftBorder.Append(leftBorder1); RightBorder rightBorder1 = new RightBorder() { Style = BorderStyleValues.Thin }; rightBorder.Append(rightBorder1); TopBorder topBorder1 = new TopBorder() { Style = BorderStyleValues.Thin }; topBorder.Append(topBorder1); BottomBorder bottomBorder1 = new BottomBorder() { Style = BorderStyleValues.Thin }; botBorder.Append(bottomBorder1); LeftBorder leftBorder2 = new LeftBorder() { Style = BorderStyleValues.Thin }; RightBorder rightBorder2 = new RightBorder() { Style = BorderStyleValues.Thin }; TopBorder topBorder2 = new TopBorder() { Style = BorderStyleValues.Thin }; BottomBorder bottomBorder2 = new BottomBorder() { Style = BorderStyleValues.Thin }; allBorder.Append(leftBorder2); allBorder.Append(rightBorder2); allBorder.Append(topBorder2); allBorder.Append(bottomBorder2); borders.Append(leftBorder); borders.Append(rightBorder); borders.Append(topBorder); borders.Append(botBorder); borders.Append(allBorder); Fonts fonts = new Fonts(); Font defFont = new Font(); FontSize dFontSize = new FontSize() { Val = 11D }; FontName dFontName = new FontName() { Val = "Calibri" }; defFont.Append(dFontSize); defFont.Append(dFontName); fonts.Append(defFont); foreach (FontStyleFormat f in fontStyleFormatList) { Font font = new Font(); if (f.Bold) { Bold bold = new Bold(); font.Append(bold); } if (f.Italic) { Italic italic = new Italic(); font.Append(italic); } if (f.Underline) { Underline underline = new Underline(); font.Append(underline); } FontSize fontSize = new FontSize() { Val = f.Size }; font.Append(fontSize); FontName fontName = new FontName() { Val = f.FontName }; font.Append(fontName); fonts.Append(font); } CellStyleFormats cellStyleFormats1 = new CellStyleFormats(); CellFormat cellFormat1 = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U }; cellStyleFormats1.Append(cellFormat1); CellFormats cellFormats = new CellFormats(); CellFormat dCellFormat = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U }; cellFormats.Append(dCellFormat); int rgbId = 1; foreach (CellStyleFormat f in cellStyleFormatList) { rgbId++; Fill fill3 = new Fill(); PatternFill patternFill3 = new PatternFill() { PatternType = PatternValues.Solid }; ForegroundColor foregroundColor1 = new ForegroundColor() { Rgb = "F" + f.RgbHtmlCode }; patternFill3.Append(foregroundColor1); fill3.Append(patternFill3); fills1.Append(fill3); int treeadsw = 0; if (f.Treead) { treeadsw = 4; } int lineStyle; switch (f.LineStyle) { default: lineStyle = 0; break; case 1: lineStyle = 1; break; case 2: lineStyle = 2; break; case 3: lineStyle = 3; break; case 4: lineStyle = 4; break; case 5: lineStyle = 5; break; } CellFormat cellFormat = new CellFormat() { NumberFormatId = (UInt32Value)(UInt32)treeadsw, FontId = (UInt32Value)(UInt32)f.FontIndex, FillId = (UInt32Value)(UInt32)rgbId, BorderId = (UInt32Value)(UInt32)lineStyle, FormatId = (UInt32Value)0U, ApplyFont = true, ApplyBorder = true, ApplyNumberFormat = f.Treead, ApplyFill = true }; cellFormats.Append(cellFormat); VerticalAlignmentValues vav; HorizontalAlignmentValues hav; switch (f.HorizontalAlignment) { default: hav = HorizontalAlignmentValues.Distributed; break; case 1: hav = HorizontalAlignmentValues.Left; break; case 2: hav = HorizontalAlignmentValues.Right; break; case 3: hav = HorizontalAlignmentValues.Center; break; } switch (f.VerticalAlignment) { default: vav = VerticalAlignmentValues.Distributed; break; case 1: vav = VerticalAlignmentValues.Bottom; break; case 2: vav = VerticalAlignmentValues.Center; break; case 3: vav = VerticalAlignmentValues.Top; break; } Alignment alignment = new Alignment() { Horizontal = hav, Vertical = vav, WrapText = f.WrapText }; cellFormat.Append(alignment); } CellStyles cellStyles1 = new CellStyles(); CellStyle cellStyle1 = new CellStyle() { Name = "Normal", FormatId = (UInt32Value)0U, BuiltinId = (UInt32Value)0U }; cellStyles1.Append(cellStyle1); DifferentialFormats differentialFormats1 = new DifferentialFormats(); TableStyles tableStyles1 = new TableStyles() { Count = (UInt32Value)0U, DefaultTableStyle = "TableStyleMedium2", DefaultPivotStyle = "PivotStyleMedium9" }; stylesheet1.Append(fonts); stylesheet1.Append(fills1); stylesheet1.Append(borders); stylesheet1.Append(cellStyleFormats1); stylesheet1.Append(cellFormats); stylesheet1.Append(cellStyles1); stylesheet1.Append(differentialFormats1); stylesheet1.Append(tableStyles1); workbookStylesPart.Stylesheet = stylesheet1; }
/// <summary> /// Создает стилевую составляющую документа /// </summary> /// <param name="workbookStylesPart">Стилевая часть книги</param> private void GenerateStyles(WorkbookStylesPart workbookStylesPart) { Stylesheet stylesheet = new Stylesheet() { MCAttributes = new MarkupCompatibilityAttributes() { Ignorable = "x14ac" } }; stylesheet.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006"); stylesheet.AddNamespaceDeclaration("x14ac", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac"); #region Fonts Fonts fonts = new Fonts() { Count = 1U, KnownFonts = true }; Font font = new Font(); FontSize fontSize = new FontSize() { Val = 11D }; Color color1 = new Color() { Theme = 1U }; FontName fontName = new FontName() { Val = "Calibri" }; FontFamilyNumbering fontFamilyNumbering = new FontFamilyNumbering() { Val = 2 }; FontCharSet fontCharSet = new FontCharSet() { Val = 204 }; FontScheme fontScheme = new FontScheme() { Val = FontSchemeValues.Minor }; font.Append(fontSize); font.Append(color1); font.Append(fontName); font.Append(fontFamilyNumbering); font.Append(fontCharSet); font.Append(fontScheme); fonts.Append(font); #endregion #region Fills Fills fills = new Fills() { Count = 2U }; Fill fill1 = new Fill(); PatternFill patternFill1 = new PatternFill() { PatternType = PatternValues.None }; fill1.Append(patternFill1); Fill fill2 = new Fill(); PatternFill patternFill2 = new PatternFill() { PatternType = PatternValues.Gray125 }; fill2.Append(patternFill2); fills.Append(fill1); fills.Append(fill2); #endregion #region Borders Borders borders = new Borders() { Count = 1U }; Border border1 = new Border(); LeftBorder leftBorder1 = new LeftBorder(); RightBorder rightBorder1 = new RightBorder(); TopBorder topBorder1 = new TopBorder(); BottomBorder bottomBorder = new BottomBorder(); DiagonalBorder diagonalBorder1 = new DiagonalBorder(); border1.Append(leftBorder1); border1.Append(rightBorder1); border1.Append(topBorder1); border1.Append(bottomBorder); border1.Append(diagonalBorder1); borders.Append(border1); #endregion #region Cell Styles And Formats CellStyleFormats cellStyleFormats = new CellStyleFormats() { Count = 1U }; CellFormat cellFormat1 = new CellFormat() { NumberFormatId = 0U, FontId = 0U, FillId = 0U, BorderId = 0U }; cellStyleFormats.Append(cellFormat1); CellFormats cellFormats = new CellFormats() { Count = 1U }; CellFormat cellFormat2 = new CellFormat() { NumberFormatId = 0U, FontId = 0U, FillId = 0U, BorderId = 0U, FormatId = 0U }; cellFormats.Append(cellFormat2); CellStyles cellStyles = new CellStyles() { Count = 1U }; CellStyle cellStyle = new CellStyle() { Name = "Обычный", FormatId = 0U, BuiltinId = 0U }; cellStyles.Append(cellStyle); #endregion DifferentialFormats differentialFormats = new DifferentialFormats() { Count = 0U }; TableStyles tableStyles = new TableStyles() { Count = 0U, DefaultTableStyle = "TableStyleMedium2", DefaultPivotStyle = "PivotStyleLight16" }; #region Stylesheet Extensions StylesheetExtensionList stylesheetExtensionList = new StylesheetExtensionList(); StylesheetExtension stylesheetExtension1 = new StylesheetExtension() { Uri = "{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}" }; stylesheetExtension1.AddNamespaceDeclaration("x14", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"); X14.SlicerStyles slicerStyles = new X14.SlicerStyles() { DefaultSlicerStyle = "SlicerStyleLight1" }; stylesheetExtension1.Append(slicerStyles); StylesheetExtension stylesheetExtension2 = new StylesheetExtension() { Uri = "{9260A510-F301-46a8-8635-F512D64BE5F5}" }; stylesheetExtension2.AddNamespaceDeclaration("x15", "http://schemas.microsoft.com/office/spreadsheetml/2010/11/main"); OpenXmlUnknownElement unknownElement = OpenXmlUnknownElement.CreateOpenXmlUnknownElement( "<x15:timelineStyles defaultTimelineStyle=\"TimeSlicerStyleLight1\" xmlns:x15=\"http://schemas.microsoft.com/office/spreadsheetml/2010/11/main\" />"); stylesheetExtension2.Append(unknownElement); stylesheetExtensionList.Append(stylesheetExtension1); stylesheetExtensionList.Append(stylesheetExtension2); #endregion stylesheet.Append(fonts); stylesheet.Append(fills); stylesheet.Append(borders); stylesheet.Append(cellStyleFormats); stylesheet.Append(cellFormats); stylesheet.Append(cellStyles); stylesheet.Append(differentialFormats); stylesheet.Append(tableStyles); stylesheet.Append(stylesheetExtensionList); workbookStylesPart.Stylesheet = stylesheet; }
public static Fill CreateFill(Fills fills, PatternValues patternType) { var fill = new Fill(); fill.Append(new PatternFill { PatternType = patternType }); fills.Append(fill); return fill; }
// Creates an Stylesheet instance and adds its children. public Stylesheet GenerateStylesheet() { Stylesheet stylesheet1 = new Stylesheet() { MCAttributes = new MarkupCompatibilityAttributes() { Ignorable = "x14ac" } }; stylesheet1.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006"); stylesheet1.AddNamespaceDeclaration("x14ac", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac"); Fonts fonts1 = new Fonts() { Count = (UInt32Value)1U }; Font font1 = new Font(); FontSize fontSize1 = new FontSize() { Val = 11D }; FontName fontName1 = new FontName() { Val = "Calibri" }; font1.Append(fontSize1); font1.Append(fontName1); fonts1.Append(font1); Fills fills1 = new Fills() { Count = (UInt32Value)2U }; Fill fill1 = new Fill(); PatternFill patternFill1 = new PatternFill() { PatternType = PatternValues.None }; fill1.Append(patternFill1); Fill fill2 = new Fill(); PatternFill patternFill2 = new PatternFill() { PatternType = PatternValues.Gray125 }; fill2.Append(patternFill2); fills1.Append(fill1); fills1.Append(fill2); Borders borders1 = new Borders() { Count = (UInt32Value)1U }; Border border1 = new Border(); LeftBorder leftBorder1 = new LeftBorder(); RightBorder rightBorder1 = new RightBorder(); TopBorder topBorder1 = new TopBorder(); BottomBorder bottomBorder1 = new BottomBorder(); DiagonalBorder diagonalBorder1 = new DiagonalBorder(); border1.Append(leftBorder1); border1.Append(rightBorder1); border1.Append(topBorder1); border1.Append(bottomBorder1); border1.Append(diagonalBorder1); Border border2 = new Border(); LeftBorder leftBorder2 = new LeftBorder() { Style = BorderStyleValues.Thin }; Color color1 = new Color() { Indexed = (UInt32Value)64U }; leftBorder2.Append(color1); RightBorder rightBorder2 = new RightBorder() { Style = BorderStyleValues.Thin }; Color color2 = new Color() { Indexed = (UInt32Value)64U }; rightBorder2.Append(color2); TopBorder topBorder2 = new TopBorder() { Style = BorderStyleValues.Thin }; Color color3 = new Color() { Indexed = (UInt32Value)64U }; topBorder2.Append(color3); BottomBorder bottomBorder2 = new BottomBorder() { Style = BorderStyleValues.Thin }; Color color4 = new Color() { Indexed = (UInt32Value)64U }; bottomBorder2.Append(color4); DiagonalBorder diagonalBorder2 = new DiagonalBorder() { Style = BorderStyleValues.Thin }; Color color5 = new Color() { Indexed = (UInt32Value)64U }; diagonalBorder2.Append(color5); border2.Append(leftBorder2); border2.Append(rightBorder2); border2.Append(topBorder2); border2.Append(bottomBorder2); border2.Append(diagonalBorder2); borders1.Append(border1); borders1.Append(border2); CellStyleFormats cellStyleFormats1 = new CellStyleFormats() { Count = (UInt32Value)1U }; CellFormat cellFormat1 = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U }; cellStyleFormats1.Append(cellFormat1); CellFormats cellFormats1 = new CellFormats() { Count = (UInt32Value)1U }; CellFormat cellFormat2 = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U }; cellFormats1.Append(cellFormat2); CellStyles cellStyles1 = new CellStyles() { Count = (UInt32Value)1U }; CellStyle cellStyle1 = new CellStyle() { Name = "Normal", FormatId = (UInt32Value)0U, BuiltinId = (UInt32Value)0U }; cellStyles1.Append(cellStyle1); DifferentialFormats differentialFormats1 = new DifferentialFormats() { Count = (UInt32Value)0U }; TableStyles tableStyles1 = new TableStyles() { Count = (UInt32Value)0U, DefaultTableStyle = "TableStyleMedium2", DefaultPivotStyle = "PivotStyleLight16" }; StylesheetExtensionList stylesheetExtensionList1 = new StylesheetExtensionList(); StylesheetExtension stylesheetExtension1 = new StylesheetExtension() { Uri = "{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}" }; stylesheetExtension1.AddNamespaceDeclaration("x14", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"); DocumentFormat.OpenXml.Office2010.Excel.SlicerStyles slicerStyles1 = new DocumentFormat.OpenXml.Office2010.Excel.SlicerStyles() { DefaultSlicerStyle = "SlicerStyleLight1" }; stylesheetExtension1.Append(slicerStyles1); stylesheetExtensionList1.Append(stylesheetExtension1); stylesheet1.Append(fonts1); stylesheet1.Append(fills1); stylesheet1.Append(borders1); stylesheet1.Append(cellStyleFormats1); stylesheet1.Append(cellFormats1); stylesheet1.Append(cellStyles1); stylesheet1.Append(differentialFormats1); stylesheet1.Append(tableStyles1); stylesheet1.Append(stylesheetExtensionList1); return stylesheet1; }
static void Main(string[] args) { var workbookClosed = new XLWorkbook(); var sheet = workbookClosed.Worksheets.Add("Sheet1"); sheet.Cell(1, 1).Value = 1; sheet.Cell(2, 1).Value = -1; workbookClosed.SaveAs("closed.xlsx"); using (SpreadsheetDocument report = SpreadsheetDocument.Open("closed.xlsx", true)) { Workbook workbook = report.WorkbookPart.Workbook; WorksheetPart worksheetPart = workbook.WorkbookPart.WorksheetParts.First(); DifferentialFormats differentialFormats = new DifferentialFormats() { Count = (UInt32Value)2U }; DifferentialFormat lessThanFormat = new DifferentialFormat(); Font lessThanFont = new Font(); lessThanFont.Append(new Condense() { Val = false }); lessThanFont.Append(new Extend() { Val = false }); lessThanFont.Append(new Color() { Rgb = "FF9C0006" }); Fill lessThanFill = new Fill(); PatternFill lessThanPatternFill = new PatternFill(); lessThanPatternFill.Append(new BackgroundColor() { Rgb = "FFFFC7CE" }); lessThanFill.Append(lessThanPatternFill); lessThanFormat.Append(lessThanFont); lessThanFormat.Append(lessThanFill); DifferentialFormat greaterThanFormat = new DifferentialFormat(); Font greaterThanFont = new Font(); greaterThanFont.Append(new Condense() { Val = false }); greaterThanFont.Append(new Extend() { Val = false }); greaterThanFont.Append(new Color() { Rgb = "FF006100" }); Fill greatherThanFill = new Fill(); PatternFill greaterThanPatternFill = new PatternFill(); greaterThanPatternFill.Append(new BackgroundColor() { Rgb = "FFC6EFCE" }); greatherThanFill.Append(greaterThanPatternFill); greaterThanFormat.Append(greaterThanFont); greaterThanFormat.Append(greatherThanFill); differentialFormats.Append(lessThanFormat); differentialFormats.Append(greaterThanFormat); workbook.WorkbookPart.WorkbookStylesPart.Stylesheet.Append(differentialFormats); ConditionalFormatting conditionalFormatting = new ConditionalFormatting() { SequenceOfReferences = new ListValue<StringValue>() { InnerText = "D2:D10" } }; ConditionalFormattingRule greaterThanRule = new ConditionalFormattingRule() { Type = ConditionalFormatValues.CellIs, FormatId = (UInt32Value)1U, Priority = 2, Operator = ConditionalFormattingOperatorValues.GreaterThan }; Formula greaterThanFormula = new Formula(); greaterThanFormula.Text = "0"; greaterThanRule.Append(greaterThanFormula); ConditionalFormattingRule lessThanRule = new ConditionalFormattingRule() { Type = ConditionalFormatValues.CellIs, FormatId = (UInt32Value)0U, Priority = 1, Operator = ConditionalFormattingOperatorValues.LessThan }; Formula lessThanFormula = new Formula(); lessThanFormula.Text = "0"; lessThanRule.Append(lessThanFormula); conditionalFormatting.Append(greaterThanRule); conditionalFormatting.Append(lessThanRule); worksheetPart.Worksheet.PrependChild<ConditionalFormatting>(conditionalFormatting); report.WorkbookPart.Workbook.Save(); report.Close(); } }
internal static Stylesheet GetStyleSheet(IEnumerable <EWStyle> styles) { //return default style; if (styles.IsNullOrEmpty()) { return(new Stylesheet( new Fonts(DefaultFont), new Fills(DefaultFill), new Borders(DefaultBorder), new CellFormats(GetDefaultCellFormat()) )); } var fontList = new List <Font>(); var fillList = new List <Fill>(); var borderList = new List <Border>(); var cellFormatList = new List <CellFormat>(); #region Fonts Fonts fonts1 = new Fonts(); fonts1.Append(GetDefaultFont()); #endregion #region Fills Fills fills1 = new Fills(); // FillId = 0 Fill fill1 = new Fill(); PatternFill patternFill1 = new PatternFill() { PatternType = PatternValues.None }; fill1.Append(patternFill1); // FillId = 1 Fill fill2 = new Fill(); PatternFill patternFill2 = new PatternFill() { PatternType = PatternValues.Gray125 }; fill2.Append(patternFill2); fills1.Append(fill1); fills1.Append(fill2); #endregion #region CellFormats CellFormats cellFormats1 = new CellFormats(); CellFormat cellFormat2 = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)1U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U, ApplyFill = true }; cellFormats1.Append(cellFormat2); #endregion #region Borders Borders borders1 = new Borders(); borders1.Append(GetDefaultBorder()); #endregion var iterationCount = 0; foreach (var item in styles) { #region Font Add Font font; if (item.Font == null) { font = GetDefaultFont(); } else { font = item.Font.oxFont; } fonts1.Append(font); #endregion #region Fill Add Fill fill; if (item.Fill == null) { fill = GetDefaultFill(); } else { fill = item.Fill.oxFill; } fills1.Append(fill); #endregion #region Border Add if (item.Border2 != null) { borders1.Append(item.Border2.oxBorder); } else { borders1.Append(GetDefaultBorder()); } #endregion #region CellFormat Add CellFormat cellFormat3 = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = UInt32Value.FromUInt32((uint)(iterationCount + 1)), FillId = UInt32Value.FromUInt32((uint)(iterationCount + 2)), BorderId = UInt32Value.FromUInt32((uint)(iterationCount == 0 ? 1 : iterationCount + 1)), ApplyFill = true, ApplyBorder = true }; cellFormats1.Append(cellFormat3); #endregion iterationCount++; EWStyle.selectors.Add(item.Selector, iterationCount.ToString()); } return(new Stylesheet( fonts1, fills1, borders1, cellFormats1 )); }
internal void Save() { var stylesPart = sd.WorkbookPart.AddNewPart <WorkbookStylesPart>(); stylesPart.Stylesheet = new Stylesheet(); CellFormats cellFormats = new CellFormats(); Fills fills = new Fills(); // There are two fills that seemingly need to be always in there Fill fill1 = new Fill(); PatternFill patternFill1 = new PatternFill(); patternFill1.PatternType = PatternValues.None; fill1.Append(patternFill1); fills.Append(fill1); Fill fill2 = new Fill(); PatternFill patternFill2 = new PatternFill(); patternFill2.PatternType = PatternValues.Gray125; fill2.Append(patternFill2); fills.Append(fill2); // And two XFs CellFormat cellFormat1 = new CellFormat(); cellFormat1.FillId = (UInt32)0; cellFormats.Append(cellFormat1); CellFormat cellFormat2 = new CellFormat(); cellFormat2.FillId = (UInt32)1; cellFormats.Append(cellFormat2); foreach (var pal in palette) { CellFormat cellFormat = new CellFormat(); cellFormat.FillId = (UInt32)(pal.Value + 2); cellFormats.Append(cellFormat); Fill fill = new Fill(); PatternFill patternFill = new PatternFill(); patternFill.PatternType = PatternValues.Solid; ForegroundColor fgc = new ForegroundColor(); fgc.Rgb = "FF" + ColorTranslator.ToHtml(pal.Key).Replace("#", ""); patternFill.Append(fgc); fill.Append(patternFill); fills.Append(fill); } // Add dummy borders and fonts, which we need for the cellXfs to work Borders borders = new Borders(); Border border = new Border(); borders.Append(border); Fonts fonts = new Fonts(); DocumentFormat.OpenXml.Spreadsheet.Font font = new DocumentFormat.OpenXml.Spreadsheet.Font(); fonts.Append(font); // Add the other things we made to the stylesheet stylesPart.Stylesheet.Append(fonts); stylesPart.Stylesheet.Append(fills); stylesPart.Stylesheet.Append(borders); stylesPart.Stylesheet.Append(cellFormats); sd.Save(); sd.Close(); }
//описвывает форматы ячеек protected void GenWorkbookStylesPart(WorkbookStylesPart workbookStylesPart) { Stylesheet stylesheet = new Stylesheet(); Fonts fonts1 = new Fonts(); Font font1 = new Font(); Font font2 = new Font(); FontSize fontSize2 = new FontSize() { Val = 11D }; Color color1 = new Color() { Rgb = "FF00B050" }; FontName fontName2 = new FontName() { Val = "Calibri" }; FontFamilyNumbering fontFamilyNumbering1 = new FontFamilyNumbering() { Val = 2 }; FontCharSet fontCharSet1 = new FontCharSet() { Val = 204 }; font2.Append(fontSize2); font2.Append(color1); font2.Append(fontName2); font2.Append(fontFamilyNumbering1); font2.Append(fontCharSet1); //fonts1.Append(font2); fonts1.Append(font1); Fills fills1 = new Fills(); Fill fill1 = new Fill(); Fill fill2 = new Fill(); Fill fill3 = new Fill(); PatternFill patternFill3 = new PatternFill() { PatternType = PatternValues.Solid }; ForegroundColor foregroundColor1 = new ForegroundColor() { Rgb = "0000FF" }; patternFill3.Append(foregroundColor1); fill3.Append(patternFill3); fills1.Append(fill1); fills1.Append(fill2); fills1.Append(fill3); Borders borders1 = new Borders(); Border border1 = new Border(); borders1.Append(border1); //Переопределяем номера формата 164U, 166U, 167U, 168U, NumberingFormats numberingFormats1 = new NumberingFormats() { Count = (UInt32Value)3U }; NumberingFormat numberingFormat1 = new NumberingFormat() { NumberFormatId = (UInt32Value)164U, FormatCode = "[$-F800]dddd\\,\\ mmmm\\ dd\\,\\ yyyy" }; NumberingFormat numberingFormat2 = new NumberingFormat() { NumberFormatId = (UInt32Value)166U, FormatCode = "#,##0.000\"р.\"" }; NumberingFormat numberingFormat3 = new NumberingFormat() { NumberFormatId = (UInt32Value)167U, FormatCode = "#,##0\"р.\"" }; //"#,##0.00\"р.\"" }; NumberingFormat numberingFormat4 = new NumberingFormat() { NumberFormatId = (UInt32Value)168U, FormatCode = "#,##0.00\"р.\"" }; numberingFormats1.Append(numberingFormat1); numberingFormats1.Append(numberingFormat2); numberingFormats1.Append(numberingFormat3); numberingFormats1.Append(numberingFormat4); CellFormats cellFormats1 = new CellFormats() { Count = (UInt32Value)6U }; CellFormat cellFormat2 = new CellFormat() { NumberFormatId = (UInt32Value)0U }; // Формат № 0 по умолчанию общий CellFormat cellFormat3 = new CellFormat() { NumberFormatId = (UInt32Value)164U }; // Формат № 1 для дат FormatCode = "[$-F800]dddd\\,\\ mmmm\\ dd\\,\\ yyyy" CellFormat cellFormat4 = new CellFormat() { NumberFormatId = (UInt32Value)166U }; //формат № 2 для денег по тысяч. ###,### <-- (number/ 1000) CellFormat cellFormat5 = new CellFormat() { NumberFormatId = (UInt32Value)14U }; //формат № 3 для дат * 14.03.2015 CellFormat cellFormat6 = new CellFormat() { NumberFormatId = (UInt32Value)2U }; //формат № 4 для чисел CellFormat cellFormat7 = new CellFormat() { NumberFormatId = (UInt32Value)1U }; //более подходящий формат № 5U для чисел (5U) CellFormat cellFormat8 = new CellFormat() { NumberFormatId = (UInt32Value)165U };//формат №6U для денег по умолчанию CellFormat cellFormat9 = new CellFormat() { NumberFormatId = (UInt32Value)167U };// формат №7U для денег(переопределенный) по три разряда ### ### р. CellFormat cellFormat10 = new CellFormat() { NumberFormatId = (UInt32Value)168U };// формат №8U для денег(переопределенный) ### ###,00 р. cellFormats1.Append(cellFormat2); cellFormats1.Append(cellFormat3); cellFormats1.Append(cellFormat4); cellFormats1.Append(cellFormat5); cellFormats1.Append(cellFormat6); cellFormats1.Append(cellFormat7); cellFormats1.Append(cellFormat8); cellFormats1.Append(cellFormat9); cellFormats1.Append(cellFormat10); stylesheet.Append(numberingFormats1); stylesheet.Append(fonts1); stylesheet.Append(fills1); stylesheet.Append(borders1); stylesheet.Append(cellFormats1); workbookStylesPart.Stylesheet = stylesheet; }
private void AddConditionalFormatting() { //use openxml directly to apply conditional formatting. using (SpreadsheetDocument report = SpreadsheetDocument.Open(fileName, true)) { Workbook workbook = report.WorkbookPart.Workbook; WorksheetPart worksheetPart = workbook.WorkbookPart.WorksheetParts.First(); DifferentialFormats differentialFormats = new DifferentialFormats() { Count = (UInt32Value)2U }; DifferentialFormat lessThanFormat = new DifferentialFormat(); Font lessThanFont = new Font(); lessThanFont.Append(new Condense() { Val = false }); lessThanFont.Append(new Extend() { Val = false }); lessThanFont.Append(new Color() { Rgb = "FF9C0006" }); Fill lessThanFill = new Fill(); PatternFill lessThanPatternFill = new PatternFill(); lessThanPatternFill.Append(new BackgroundColor() { Rgb = "FFFFC7CE" }); lessThanFill.Append(lessThanPatternFill); lessThanFormat.Append(lessThanFont); lessThanFormat.Append(lessThanFill); DifferentialFormat greaterThanFormat = new DifferentialFormat(); Font greaterThanFont = new Font(); greaterThanFont.Append(new Condense() { Val = false }); greaterThanFont.Append(new Extend() { Val = false }); greaterThanFont.Append(new Color() { Rgb = "FF006100" }); Fill greatherThanFill = new Fill(); PatternFill greaterThanPatternFill = new PatternFill(); greaterThanPatternFill.Append(new BackgroundColor() { Rgb = "FFC6EFCE" }); greatherThanFill.Append(greaterThanPatternFill); greaterThanFormat.Append(greaterThanFont); greaterThanFormat.Append(greatherThanFill); differentialFormats.Append(lessThanFormat); differentialFormats.Append(greaterThanFormat); workbook.WorkbookPart.WorkbookStylesPart.Stylesheet.Append(differentialFormats); ConditionalFormatting conditionalFormatting = new ConditionalFormatting() { SequenceOfReferences = new ListValue<StringValue>() { InnerText = "D2:D10" } }; ConditionalFormattingRule greaterThanRule = new ConditionalFormattingRule() { Type = ConditionalFormatValues.CellIs, FormatId = (UInt32Value)1U, Priority = 2, Operator = ConditionalFormattingOperatorValues.GreaterThan }; Formula greaterThanFormula = new Formula(); greaterThanFormula.Text = "0"; greaterThanRule.Append(greaterThanFormula); ConditionalFormattingRule lessThanRule = new ConditionalFormattingRule() { Type = ConditionalFormatValues.CellIs, FormatId = (UInt32Value)0U, Priority = 1, Operator = ConditionalFormattingOperatorValues.LessThan }; Formula lessThanFormula = new Formula(); lessThanFormula.Text = "0"; lessThanRule.Append(lessThanFormula); conditionalFormatting.Append(greaterThanRule); conditionalFormatting.Append(lessThanRule); worksheetPart.Worksheet.Append(conditionalFormatting); report.WorkbookPart.Workbook.Save(); report.Close(); } }
public static Stylesheet GenerateStylesheet() { Stylesheet stylesheet1 = new Stylesheet() { MCAttributes = new MarkupCompatibilityAttributes() { Ignorable = "x14ac" } }; stylesheet1.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006"); stylesheet1.AddNamespaceDeclaration("x14ac", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac"); Fonts fonts1 = new Fonts() { Count = (UInt32Value)3U, KnownFonts = true }; Font font1 = new Font(); FontSize fontSize1 = new FontSize() { Val = 14D }; Color color1 = new Color() { Theme = (UInt32Value)1U }; FontName fontName1 = new FontName() { Val = "Calibri" }; FontFamilyNumbering fontFamilyNumbering1 = new FontFamilyNumbering() { Val = 2 }; FontScheme fontScheme1 = new FontScheme() { Val = FontSchemeValues.Minor }; font1.Append(fontSize1); font1.Append(color1); font1.Append(fontName1); font1.Append(fontFamilyNumbering1); font1.Append(fontScheme1); Font font2 = new Font(); Bold bold2 = new Bold(); FontSize fontSize2 = new FontSize() { Val = 18D }; Color color2 = new Color() { Theme = (UInt32Value)1U }; FontName fontName2 = new FontName() { Val = "Calibri" }; FontFamilyNumbering fontFamilyNumbering2 = new FontFamilyNumbering() { Val = 2 }; FontScheme fontScheme2 = new FontScheme() { Val = FontSchemeValues.Minor }; font2.Append(bold2); font2.Append(fontSize2); font2.Append(color2); font2.Append(fontName2); font2.Append(fontFamilyNumbering2); font2.Append(fontScheme2); Font font3 = new Font(); Bold bold1 = new Bold(); FontSize fontSize3 = new FontSize() { Val = 30D }; Color color3 = new Color() { Theme = (UInt32Value)1U }; FontName fontName3 = new FontName() { Val = "Calibri" }; FontFamilyNumbering fontFamilyNumbering3 = new FontFamilyNumbering() { Val = 2 }; FontScheme fontScheme3 = new FontScheme() { Val = FontSchemeValues.Minor }; font3.Append(bold1); font3.Append(fontSize3); font3.Append(color3); font3.Append(fontName3); font3.Append(fontFamilyNumbering3); font3.Append(fontScheme3); fonts1.Append(font1); fonts1.Append(font2); fonts1.Append(font3); Fills fills1 = new Fills() { Count = (UInt32Value)2U }; // 0 no BG color just normal Excel Fill fill1 = new Fill(); PatternFill patternFill1 = new PatternFill() { PatternType = PatternValues.None }; fill1.Append(patternFill1); // 1 red or open CAT 1 Fill fill2 = new Fill(); PatternFill patternFill2 = new PatternFill() { PatternType = PatternValues.Solid }; ForegroundColor foregroundColor2 = new ForegroundColor() { Rgb = "FFFF0000" }; BackgroundColor backgroundColor2 = new BackgroundColor() { Indexed = (UInt32Value)64U }; patternFill2.Append(foregroundColor2); patternFill2.Append(backgroundColor2); fill2.Append(patternFill2); // 2 silver or N/A Fill fill3 = new Fill(); PatternFill patternFill3 = new PatternFill() { PatternType = PatternValues.Solid }; ForegroundColor foregroundColor3 = new ForegroundColor() { Rgb = "FFCCCCCC" }; BackgroundColor backgroundColor3 = new BackgroundColor() { Indexed = (UInt32Value)64U }; patternFill3.Append(foregroundColor3); patternFill3.Append(backgroundColor3); fill3.Append(patternFill3); // 3 green or NaF Fill fill4 = new Fill(); PatternFill patternFill4 = new PatternFill() { PatternType = PatternValues.Solid }; ForegroundColor foregroundColor4 = new ForegroundColor() { Rgb = "FF50CC83" }; BackgroundColor backgroundColor4 = new BackgroundColor() { Indexed = (UInt32Value)64U }; patternFill4.Append(foregroundColor4); patternFill4.Append(backgroundColor4); fill4.Append(patternFill4); // 4 black&white or Not Reviewed Fill fill5 = new Fill(); PatternFill patternFill5 = new PatternFill() { PatternType = PatternValues.Solid }; ForegroundColor foregroundColor5 = new ForegroundColor() { Rgb = "FFFFFFFF" }; BackgroundColor backgroundColor5 = new BackgroundColor() { Indexed = (UInt32Value)64U }; patternFill5.Append(foregroundColor5); patternFill5.Append(backgroundColor5); fill5.Append(patternFill5); // 5 red or open CAT 1 Fill fill6 = new Fill(); PatternFill patternFill6 = new PatternFill() { PatternType = PatternValues.Solid }; ForegroundColor foregroundColor6 = new ForegroundColor() { Rgb = "FFE53935" }; BackgroundColor backgroundColor6 = new BackgroundColor() { Indexed = (UInt32Value)64U }; patternFill6.Append(foregroundColor6); patternFill6.Append(backgroundColor6); fill6.Append(patternFill6); // 6 orange open CAT 2 Fill fill7 = new Fill(); PatternFill patternFill7 = new PatternFill() { PatternType = PatternValues.Solid }; ForegroundColor foregroundColor7 = new ForegroundColor() { Rgb = "FFFFA500" }; BackgroundColor backgroundColor7 = new BackgroundColor() { Indexed = (UInt32Value)64U }; patternFill7.Append(foregroundColor7); patternFill7.Append(backgroundColor7); fill7.Append(patternFill7); // 7 orange open CAT 3 Fill fill8 = new Fill(); PatternFill patternFill8 = new PatternFill() { PatternType = PatternValues.Solid }; ForegroundColor foregroundColor8 = new ForegroundColor() { Rgb = "FFD8D80E" }; BackgroundColor backgroundColor8 = new BackgroundColor() { Indexed = (UInt32Value)64U }; patternFill8.Append(foregroundColor8); patternFill8.Append(backgroundColor8); fill8.Append(patternFill8); // 8 gray background for any general use Fill fill9 = new Fill(); PatternFill patternFill9 = new PatternFill() { PatternType = PatternValues.Solid }; ForegroundColor foregroundColor9 = new ForegroundColor() { Rgb = "FFBBBBBB" }; BackgroundColor backgroundColor9 = new BackgroundColor() { Indexed = (UInt32Value)64U }; patternFill9.Append(foregroundColor9); patternFill9.Append(backgroundColor9); fill9.Append(patternFill9); fills1.Append(fill1); // these are 0 based when you include in the CellFormat statements below, so 1 off fills1.Append(fill2); fills1.Append(fill3); fills1.Append(fill4); fills1.Append(fill5); fills1.Append(fill6); fills1.Append(fill7); fills1.Append(fill8); fills1.Append(fill9); Borders borders1 = new Borders() { Count = (UInt32Value)1U }; Border border1 = new Border(); LeftBorder leftBorder1 = new LeftBorder(); RightBorder rightBorder1 = new RightBorder(); TopBorder topBorder1 = new TopBorder(); BottomBorder bottomBorder1 = new BottomBorder(); DiagonalBorder diagonalBorder1 = new DiagonalBorder(); border1.Append(leftBorder1); border1.Append(rightBorder1); border1.Append(topBorder1); border1.Append(bottomBorder1); border1.Append(diagonalBorder1); borders1.Append(border1); CellStyleFormats cellStyleFormats1 = new CellStyleFormats() { Count = (UInt32Value)1U }; CellFormat cellFormat1 = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U }; cellStyleFormats1.Append(cellFormat1); CellFormats cellFormats1 = new CellFormats() { Count = (UInt32Value)4U }; // style index 0: normal font and wrapping of text for cell rows CellFormat cellFormat2 = new CellFormat(new Alignment() { WrapText = true }) { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U }; // style index 1: normal font with numerical format CellFormat cellFormat3 = new CellFormat(new Alignment() { WrapText = true }) { NumberFormatId = (UInt32Value)2U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U, ApplyNumberFormat = true }; // style index 2: title font of 30 bold CellFormat cellFormat4 = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)2U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U, ApplyFont = true }; // style index 3: info row under title and header rows font bold size 18 CellFormat cellFormat5 = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)1U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U, ApplyFont = true }; // fill colors based on the fillx variables above to match the 4 statuses of the checklist vulnerabilities // style index 4: red or Open CellFormat cellFormat6 = new CellFormat(new Alignment() { WrapText = true }) { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)5U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U }; // style index 5: silver or Not Applicable CellFormat cellFormat7 = new CellFormat(new Alignment() { WrapText = true }) { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)2U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U }; // style index 6: green or Not a Finding CellFormat cellFormat8 = new CellFormat(new Alignment() { WrapText = true }) { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)3U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U }; // style index 7: b/w or Not Reviewed CellFormat cellFormat9 = new CellFormat(new Alignment() { WrapText = true }) { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)4U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U }; // CENTER The content for listings versus the excel export of a checklist above // style index 8: red or Open centered content CellFormat cellFormat10 = new CellFormat(new Alignment() { WrapText = true, Horizontal = HorizontalAlignmentValues.Center }) { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)5U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U }; // style index 9: silver or Not Applicable CellFormat cellFormat11 = new CellFormat(new Alignment() { WrapText = true, Horizontal = HorizontalAlignmentValues.Center }) { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)2U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U }; // style index 10: green or Not a Finding CellFormat cellFormat12 = new CellFormat(new Alignment() { WrapText = true, Horizontal = HorizontalAlignmentValues.Center }) { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)3U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U }; // style index 11: b/w or Not Reviewed CellFormat cellFormat13 = new CellFormat(new Alignment() { WrapText = true, Horizontal = HorizontalAlignmentValues.Center }) { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)4U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U }; // style index 12: orange Open CAT 2 CellFormat cellFormat14 = new CellFormat(new Alignment() { WrapText = true }) { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)6U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U }; // style index 13: yellow Open CAT 3 CellFormat cellFormat15 = new CellFormat(new Alignment() { WrapText = true }) { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)7U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U }; // style index 14: orange Open CAT 2 centered CellFormat cellFormat16 = new CellFormat(new Alignment() { WrapText = true, Horizontal = HorizontalAlignmentValues.Center }) { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)6U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U }; // style index 15: yellow Open CAT 3 centered CellFormat cellFormat17 = new CellFormat(new Alignment() { WrapText = true, Horizontal = HorizontalAlignmentValues.Center }) { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)7U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U }; // style index 16: yellow Open CAT 3 centered CellFormat cellFormat18 = new CellFormat(new Alignment() { WrapText = true }) { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)1U, FillId = (UInt32Value)8U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U, ApplyFont = true }; // add all these formats cellFormats1.Append(cellFormat2); cellFormats1.Append(cellFormat3); cellFormats1.Append(cellFormat4); cellFormats1.Append(cellFormat5); cellFormats1.Append(cellFormat6); cellFormats1.Append(cellFormat7); cellFormats1.Append(cellFormat8); cellFormats1.Append(cellFormat9); cellFormats1.Append(cellFormat10); cellFormats1.Append(cellFormat11); cellFormats1.Append(cellFormat12); cellFormats1.Append(cellFormat13); cellFormats1.Append(cellFormat14); cellFormats1.Append(cellFormat15); cellFormats1.Append(cellFormat16); cellFormats1.Append(cellFormat17); cellFormats1.Append(cellFormat18); CellStyles cellStyles1 = new CellStyles() { Count = (UInt32Value)1U }; CellStyle cellStyle1 = new CellStyle() { Name = "Normal", FormatId = 0, BuiltinId = 0 }; cellStyles1.Append(cellStyle1); DifferentialFormats differentialFormats1 = new DifferentialFormats() { Count = 0 }; TableStyles tableStyles1 = new TableStyles() { Count = 0, DefaultTableStyle = "TableStyleMedium2", DefaultPivotStyle = "PivotStyleLight16" }; StylesheetExtensionList stylesheetExtensionList1 = new StylesheetExtensionList(); StylesheetExtension stylesheetExtension1 = new StylesheetExtension() { Uri = "{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}" }; stylesheetExtension1.AddNamespaceDeclaration("x14", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"); StylesheetExtension stylesheetExtension2 = new StylesheetExtension() { Uri = "{9260A510-F301-46a8-8635-F512D64BE5F5}" }; stylesheetExtension2.AddNamespaceDeclaration("x15", "http://schemas.microsoft.com/office/spreadsheetml/2010/11/main"); stylesheetExtensionList1.Append(stylesheetExtension1); stylesheetExtensionList1.Append(stylesheetExtension2); stylesheet1.Append(fonts1); stylesheet1.Append(fills1); stylesheet1.Append(borders1); stylesheet1.Append(cellStyleFormats1); stylesheet1.Append(cellFormats1); stylesheet1.Append(cellStyles1); stylesheet1.Append(differentialFormats1); stylesheet1.Append(tableStyles1); stylesheet1.Append(stylesheetExtensionList1); return(stylesheet1); }
private static void CreateStyles(WorkbookPart workbookpart) { WorkbookStylesPart sp = workbookpart.AddNewPart <WorkbookStylesPart>(); sp.Stylesheet = new Stylesheet(); Fonts fonts = new Fonts() { Count = (UInt32Value)2U, KnownFonts = true }; Font fontUsual = new Font(); fontUsual.Append(new FontSize() { Val = 12D }); fontUsual.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Theme = (UInt32Value)1U }); fontUsual.Append(new FontName() { Val = "Times New Roman" }); fontUsual.Append(new FontFamilyNumbering() { Val = 2 }); fontUsual.Append(new FontScheme() { Val = FontSchemeValues.Minor }); Font fontTitle = new Font(); fontTitle.Append(new Bold()); fontTitle.Append(new FontSize() { Val = 14D }); fontTitle.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Theme = (UInt32Value)1U }); fontTitle.Append(new FontName() { Val = "Times New Roman" }); fontTitle.Append(new FontFamilyNumbering() { Val = 2 }); fontTitle.Append(new FontScheme() { Val = FontSchemeValues.Minor }); fonts.Append(fontUsual); fonts.Append(fontTitle); Fills fills = new Fills() { Count = (UInt32Value)2U }; Fill fill1 = new Fill(); fill1.Append(new PatternFill() { PatternType = PatternValues.None }); Fill fill2 = new Fill(); fill2.Append(new PatternFill() { PatternType = PatternValues.Gray125 }); fills.Append(fill1); fills.Append(fill2); Borders borders = new Borders() { Count = (UInt32Value)2U }; Border borderNoBorder = new Border(); borderNoBorder.Append(new LeftBorder()); borderNoBorder.Append(new RightBorder()); borderNoBorder.Append(new TopBorder()); borderNoBorder.Append(new BottomBorder()); borderNoBorder.Append(new DiagonalBorder()); Border borderThin = new Border(); LeftBorder leftBorder = new LeftBorder() { Style = BorderStyleValues.Thin }; leftBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = (UInt32Value)64U }); RightBorder rightBorder = new RightBorder() { Style = BorderStyleValues.Thin }; rightBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = (UInt32Value)64U }); TopBorder topBorder = new TopBorder() { Style = BorderStyleValues.Thin }; topBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = (UInt32Value)64U }); BottomBorder bottomBorder = new BottomBorder() { Style = BorderStyleValues.Thin }; bottomBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = (UInt32Value)64U }); borderThin.Append(leftBorder); borderThin.Append(rightBorder); borderThin.Append(topBorder); borderThin.Append(bottomBorder); borderThin.Append(new DiagonalBorder()); borders.Append(borderNoBorder); borders.Append(borderThin); CellStyleFormats cellStyleFormats = new CellStyleFormats() { Count = (UInt32Value)1U }; CellFormat cellFormatStyle = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U }; cellStyleFormats.Append(cellFormatStyle); CellFormats cellFormats = new CellFormats() { Count = (UInt32Value)3U }; CellFormat cellFormatFont = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U, ApplyFont = true }; CellFormat cellFormatFontAndBorder = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)1U, FormatId = (UInt32Value)0U, ApplyFont = true, ApplyBorder = true }; CellFormat cellFormatTitle = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)1U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U, Alignment = new Alignment() { Vertical = VerticalAlignmentValues.Center, WrapText = true, Horizontal = HorizontalAlignmentValues.Center }, ApplyFont = true }; cellFormats.Append(cellFormatFont); cellFormats.Append(cellFormatFontAndBorder); cellFormats.Append(cellFormatTitle); CellStyles cellStyles = new CellStyles() { Count = (UInt32Value)1U }; cellStyles.Append(new CellStyle() { Name = "Normal", FormatId = (UInt32Value)0U, BuiltinId = (UInt32Value)0U }); DocumentFormat.OpenXml.Office2013.Excel.DifferentialFormats differentialFormats = new DocumentFormat.OpenXml.Office2013.Excel.DifferentialFormats() { Count = (UInt32Value)0U }; TableStyles tableStyles = new TableStyles() { Count = (UInt32Value)0U, DefaultTableStyle = "TableStyleMedium2", DefaultPivotStyle = "PivotStyleLight16" }; StylesheetExtensionList stylesheetExtensionList = new StylesheetExtensionList(); StylesheetExtension stylesheetExtension1 = new StylesheetExtension() { Uri = "{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}" }; stylesheetExtension1.AddNamespaceDeclaration("x14", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"); stylesheetExtension1.Append(new SlicerStyles() { DefaultSlicerStyle = "SlicerStyleLight1" }); StylesheetExtension stylesheetExtension2 = new StylesheetExtension() { Uri = "{9260A510-F301-46a8-8635-F512D64BE5F5}" }; stylesheetExtension2.AddNamespaceDeclaration("x15", "http://schemas.microsoft.com/office/spreadsheetml/2010/11/main"); stylesheetExtension2.Append(new TimelineStyles() { DefaultTimelineStyle = "TimeSlicerStyleLight1" }); stylesheetExtensionList.Append(stylesheetExtension1); stylesheetExtensionList.Append(stylesheetExtension2); sp.Stylesheet.Append(fonts); sp.Stylesheet.Append(fills); sp.Stylesheet.Append(borders); sp.Stylesheet.Append(cellStyleFormats); sp.Stylesheet.Append(cellFormats); sp.Stylesheet.Append(cellStyles); sp.Stylesheet.Append(differentialFormats); sp.Stylesheet.Append(tableStyles); sp.Stylesheet.Append(stylesheetExtensionList); }
private static Stylesheet CreateStylesheet() { // Stylesheet declarion and namespace Stylesheet stylesheet = new Stylesheet() { MCAttributes = new MarkupCompatibilityAttributes() { Ignorable = "x14ac" } }; stylesheet.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006"); stylesheet.AddNamespaceDeclaration("x14ac", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac"); // List of fonts Fonts fontsList = new Fonts() { Count = (UInt32Value)2U, KnownFonts = true }; // FontId=0 - Regular Excel font Font font0 = new Font(); FontSize fontSize0 = new FontSize() { Val = 11D }; Color color0 = new Color() { Theme = (UInt32Value)1U }; FontName fontName0 = new FontName() { Val = "Calibri" }; FontFamilyNumbering fontFamilyNumbering0 = new FontFamilyNumbering() { Val = 2 }; FontScheme fontScheme0 = new FontScheme() { Val = FontSchemeValues.Minor }; font0.Append(fontSize0); font0.Append(color0); font0.Append(fontName0); font0.Append(fontFamilyNumbering0); font0.Append(fontScheme0); // FontId=1 - Bold font for header Font font1 = new Font(); Bold bold = new Bold(); font1.Append(bold); fontsList.Append(font0); fontsList.Append(font1); // List of fills Fills fillList = new Fills() { Count = (UInt32Value)3U }; // FillId = 0, Normal background Fill fill0 = new Fill(); PatternFill patternFill0 = new PatternFill() { PatternType = PatternValues.None }; fill0.Append(patternFill0); // FillId = 00, Normal background Fill fill00 = new Fill(); PatternFill patternFill00 = new PatternFill() { PatternType = PatternValues.None }; fill00.Append(patternFill00); // FillId = 1, Light Blue for alternating cells Fill fill1 = new Fill(); PatternFill patternFill1 = new PatternFill() { PatternType = PatternValues.Solid }; ForegroundColor foregroundColor1 = new ForegroundColor() { Rgb = "FFDEEFF7" }; patternFill1.Append(foregroundColor1); fill1.Append(patternFill1); fillList.Append(fill0); fillList.Append(fill00); fillList.Append(fill1); // Borders style Borders bordersList = new Borders() { Count = (UInt32Value)1U }; Border border1 = new Border(); LeftBorder leftBorder1 = new LeftBorder(); RightBorder rightBorder1 = new RightBorder(); TopBorder topBorder1 = new TopBorder(); BottomBorder bottomBorder1 = new BottomBorder(); DiagonalBorder diagonalBorder1 = new DiagonalBorder(); border1.Append(leftBorder1); border1.Append(rightBorder1); border1.Append(topBorder1); border1.Append(bottomBorder1); border1.Append(diagonalBorder1); bordersList.Append(border1); // List of cell styles formats CellStyleFormats cellStyleFormatsList = new CellStyleFormats() { Count = (UInt32Value)1U }; CellFormat cellFormat = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U }; cellStyleFormatsList.Append(cellFormat); // Cells formats CellFormats cellFormatsList = new CellFormats() { Count = (UInt32Value)5U }; // StyleIndex = 0 - Regular font CellFormat cellFormat0 = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U }; // StyleIndex = 1 - Bold font CellFormat cellFormat1 = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)1U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U }; // StyleIndex = 2 - Date (Short Date) CellFormat cellFormat2 = new CellFormat() { NumberFormatId = (UInt32Value)14U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U }; // StyleIndex = 3 - Light blue background (Text and Numbers) CellFormat cellFormat3 = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)2U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U, ApplyFill = true }; // StyleIndex = 4 - Light blue background (Date) CellFormat cellFormat4 = new CellFormat() { NumberFormatId = (UInt32Value)14U, FontId = (UInt32Value)0U, FillId = (UInt32Value)2U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U, ApplyFill = true }; cellFormatsList.Append(cellFormat0); cellFormatsList.Append(cellFormat1); cellFormatsList.Append(cellFormat2); cellFormatsList.Append(cellFormat3); cellFormatsList.Append(cellFormat4); // Cells styles CellStyles cellStyleList = new CellStyles() { Count = (UInt32Value)1U }; CellStyle cellStyle0 = new CellStyle() { Name = "Normal", FormatId = (UInt32Value)0U, BuiltinId = (UInt32Value)0U }; cellStyleList.Append(cellStyle0); DifferentialFormats differentialFormats0 = new DifferentialFormats() { Count = (UInt32Value)0U }; TableStyles tableStyles0 = new TableStyles() { Count = (UInt32Value)0U, DefaultTableStyle = "TableStyleMedium2", DefaultPivotStyle = "PivotStyleMedium9" }; StylesheetExtensionList stylesheetExtensionList = new StylesheetExtensionList(); StylesheetExtension stylesheetExtension1 = new StylesheetExtension() { Uri = "{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}" }; stylesheetExtensionList.Append(stylesheetExtension1); stylesheet.Append(fontsList); stylesheet.Append(fillList); stylesheet.Append(bordersList); stylesheet.Append(cellStyleFormatsList); stylesheet.Append(cellFormatsList); stylesheet.Append(cellStyleList); stylesheet.Append(differentialFormats0); stylesheet.Append(tableStyles0); stylesheet.Append(stylesheetExtensionList); return(stylesheet); }
// Creates an Stylesheet instance and adds its children. public static Stylesheet GenerateStylesheet() { var stylesheet1 = new Stylesheet {MCAttributes = new MarkupCompatibilityAttributes {Ignorable = "x14ac"}}; stylesheet1.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006"); stylesheet1.AddNamespaceDeclaration("x14ac", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac"); var fonts1 = new Fonts {Count = 7U, KnownFonts = true}; var font1 = new Font(); var fontSize1 = new FontSize {Val = 11D}; var color1 = new Color {Theme = 1U}; var fontName1 = new FontName {Val = "Calibri"}; var fontFamilyNumbering1 = new FontFamilyNumbering {Val = 2}; var fontCharSet1 = new FontCharSet {Val = 204}; var fontScheme1 = new FontScheme {Val = FontSchemeValues.Minor}; font1.Append(fontSize1); font1.Append(color1); font1.Append(fontName1); font1.Append(fontFamilyNumbering1); font1.Append(fontCharSet1); font1.Append(fontScheme1); var font2 = new Font(); var bold1 = new Bold(); var fontSize2 = new FontSize {Val = 11D}; var color2 = new Color {Theme = 1U}; var fontName2 = new FontName {Val = "Calibri"}; var fontFamilyNumbering2 = new FontFamilyNumbering {Val = 2}; var fontCharSet2 = new FontCharSet {Val = 204}; var fontScheme2 = new FontScheme {Val = FontSchemeValues.Minor}; font2.Append(bold1); font2.Append(fontSize2); font2.Append(color2); font2.Append(fontName2); font2.Append(fontFamilyNumbering2); font2.Append(fontCharSet2); font2.Append(fontScheme2); var font3 = new Font(); var bold2 = new Bold(); var italic1 = new Italic(); var fontSize3 = new FontSize {Val = 11D}; var color3 = new Color {Theme = 1U}; var fontName3 = new FontName {Val = "Calibri"}; var fontFamilyNumbering3 = new FontFamilyNumbering {Val = 2}; var fontCharSet3 = new FontCharSet {Val = 204}; var fontScheme3 = new FontScheme {Val = FontSchemeValues.Minor}; font3.Append(bold2); font3.Append(italic1); font3.Append(fontSize3); font3.Append(color3); font3.Append(fontName3); font3.Append(fontFamilyNumbering3); font3.Append(fontCharSet3); font3.Append(fontScheme3); var font4 = new Font(); var bold3 = new Bold(); var fontSize4 = new FontSize {Val = 18D}; var color4 = new Color {Theme = 1U}; var fontName4 = new FontName {Val = "Calibri"}; var fontFamilyNumbering4 = new FontFamilyNumbering {Val = 2}; var fontCharSet4 = new FontCharSet {Val = 204}; var fontScheme4 = new FontScheme {Val = FontSchemeValues.Minor}; font4.Append(bold3); font4.Append(fontSize4); font4.Append(color4); font4.Append(fontName4); font4.Append(fontFamilyNumbering4); font4.Append(fontCharSet4); font4.Append(fontScheme4); var font5 = new Font(); var bold4 = new Bold(); var fontSize5 = new FontSize {Val = 11D}; var fontName5 = new FontName {Val = "Calibri"}; var fontFamilyNumbering5 = new FontFamilyNumbering {Val = 2}; var fontCharSet5 = new FontCharSet {Val = 204}; var fontScheme5 = new FontScheme {Val = FontSchemeValues.Minor}; font5.Append(bold4); font5.Append(fontSize5); font5.Append(fontName5); font5.Append(fontFamilyNumbering5); font5.Append(fontCharSet5); font5.Append(fontScheme5); var font6 = new Font(); var fontSize6 = new FontSize {Val = 11D}; var fontName6 = new FontName {Val = "Calibri"}; var fontFamilyNumbering6 = new FontFamilyNumbering {Val = 2}; var fontCharSet6 = new FontCharSet {Val = 204}; var fontScheme6 = new FontScheme {Val = FontSchemeValues.Minor}; font6.Append(fontSize6); font6.Append(fontName6); font6.Append(fontFamilyNumbering6); font6.Append(fontCharSet6); font6.Append(fontScheme6); var font7 = new Font(); var bold5 = new Bold(); var fontSize7 = new FontSize {Val = 12D}; var color5 = new Color {Theme = 1U}; var fontName7 = new FontName {Val = "Calibri"}; var fontFamilyNumbering7 = new FontFamilyNumbering {Val = 2}; var fontCharSet7 = new FontCharSet {Val = 204}; var fontScheme7 = new FontScheme {Val = FontSchemeValues.Minor}; font7.Append(bold5); font7.Append(fontSize7); font7.Append(color5); font7.Append(fontName7); font7.Append(fontFamilyNumbering7); font7.Append(fontCharSet7); font7.Append(fontScheme7); fonts1.Append(font1); fonts1.Append(font2); fonts1.Append(font3); fonts1.Append(font4); fonts1.Append(font5); fonts1.Append(font6); fonts1.Append(font7); var fills1 = new Fills {Count = 2U}; var fill1 = new Fill(); var patternFill1 = new PatternFill {PatternType = PatternValues.None}; fill1.Append(patternFill1); var fill2 = new Fill(); var patternFill2 = new PatternFill {PatternType = PatternValues.Gray125}; fill2.Append(patternFill2); fills1.Append(fill1); fills1.Append(fill2); var borders1 = new Borders {Count = 2U}; var border1 = new Border(); var leftBorder1 = new LeftBorder(); var rightBorder1 = new RightBorder(); var topBorder1 = new TopBorder(); var bottomBorder1 = new BottomBorder(); var diagonalBorder1 = new DiagonalBorder(); border1.Append(leftBorder1); border1.Append(rightBorder1); border1.Append(topBorder1); border1.Append(bottomBorder1); border1.Append(diagonalBorder1); var border2 = new Border(); var leftBorder2 = new LeftBorder {Style = BorderStyleValues.Thin}; var color6 = new Color {Indexed = 64U}; leftBorder2.Append(color6); var rightBorder2 = new RightBorder {Style = BorderStyleValues.Thin}; var color7 = new Color {Indexed = 64U}; rightBorder2.Append(color7); var topBorder2 = new TopBorder {Style = BorderStyleValues.Thin}; var color8 = new Color {Indexed = 64U}; topBorder2.Append(color8); var bottomBorder2 = new BottomBorder {Style = BorderStyleValues.Thin}; var color9 = new Color {Indexed = 64U}; bottomBorder2.Append(color9); var diagonalBorder2 = new DiagonalBorder(); border2.Append(leftBorder2); border2.Append(rightBorder2); border2.Append(topBorder2); border2.Append(bottomBorder2); border2.Append(diagonalBorder2); borders1.Append(border1); borders1.Append(border2); var cellStyleFormats1 = new CellStyleFormats {Count = 4U}; var cellFormat1 = new CellFormat {NumberFormatId = 0U, FontId = 0U, FillId = 0U, BorderId = 0U}; var cellFormat2 = new CellFormat { NumberFormatId = 0U, FontId = 5U, FillId = 0U, BorderId = 1U, ApplyNumberFormat = false, ApplyAlignment = false, ApplyProtection = false }; var cellFormat3 = new CellFormat { NumberFormatId = 0U, FontId = 4U, FillId = 0U, BorderId = 1U, ApplyNumberFormat = false, ApplyAlignment = false, ApplyProtection = false }; var cellFormat4 = new CellFormat {NumberFormatId = 0U, FontId = 6U, FillId = 0U, BorderId = 1U}; cellStyleFormats1.Append(cellFormat1); cellStyleFormats1.Append(cellFormat2); cellStyleFormats1.Append(cellFormat3); cellStyleFormats1.Append(cellFormat4); var cellFormats1 = new CellFormats {Count = 5U}; var cellFormat5 = new CellFormat { NumberFormatId = 0U, FontId = 0U, FillId = 0U, BorderId = 0U, FormatId = 0U }; var cellFormat6 = new CellFormat { NumberFormatId = 0U, FontId = 1U, FillId = 0U, BorderId = 0U, FormatId = 0U, ApplyFont = true }; var cellFormat7 = new CellFormat { NumberFormatId = 0U, FontId = 2U, FillId = 0U, BorderId = 0U, FormatId = 0U, ApplyFont = true, ApplyBorder = true }; var cellFormat8 = new CellFormat { NumberFormatId = 0U, FontId = 0U, FillId = 0U, BorderId = 0U, FormatId = 0U, ApplyAlignment = true }; var cellFormat9 = new CellFormat { NumberFormatId = 0U, FontId = 3U, FillId = 0U, BorderId = 0U, FormatId = 0U, ApplyFont = true, ApplyAlignment = true }; var alignment1 = new Alignment {Horizontal = HorizontalAlignmentValues.Center}; cellFormat9.Append(alignment1); cellFormats1.Append(cellFormat5); cellFormats1.Append(cellFormat6); cellFormats1.Append(cellFormat7); cellFormats1.Append(cellFormat8); cellFormats1.Append(cellFormat9); var cellStyles1 = new CellStyles {Count = 4U}; var cellStyle1 = new CellStyle {Name = "Custom", FormatId = 3U}; var cellStyle2 = new CellStyle {Name = "Нейтральный", FormatId = 2U, BuiltinId = 28U, CustomBuiltin = true}; var cellStyle3 = new CellStyle {Name = "Обычный", FormatId = 0U, BuiltinId = 0U}; var cellStyle4 = new CellStyle {Name = "Плохой", FormatId = 1U, BuiltinId = 27U, CustomBuiltin = true}; cellStyles1.Append(cellStyle1); cellStyles1.Append(cellStyle2); cellStyles1.Append(cellStyle3); cellStyles1.Append(cellStyle4); var differentialFormats1 = new DifferentialFormats {Count = 0U}; var tableStyles1 = new TableStyles { Count = 0U, DefaultTableStyle = "TableStyleMedium2", DefaultPivotStyle = "PivotStyleLight16" }; var stylesheetExtensionList1 = new StylesheetExtensionList(); var stylesheetExtension1 = new StylesheetExtension {Uri = "{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}"}; stylesheetExtension1.AddNamespaceDeclaration("x14", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"); var slicerStyles1 = new X14.SlicerStyles {DefaultSlicerStyle = "SlicerStyleLight1"}; stylesheetExtension1.Append(slicerStyles1); stylesheetExtensionList1.Append(stylesheetExtension1); stylesheet1.Append(fonts1); stylesheet1.Append(fills1); stylesheet1.Append(borders1); stylesheet1.Append(cellStyleFormats1); stylesheet1.Append(cellFormats1); stylesheet1.Append(cellStyles1); stylesheet1.Append(differentialFormats1); stylesheet1.Append(tableStyles1); stylesheet1.Append(stylesheetExtensionList1); return stylesheet1; }
private static Stylesheet CreateStylesheet() { Stylesheet stylesheet1 = new Stylesheet() { MCAttributes = new MarkupCompatibilityAttributes() { Ignorable = "x14ac" } }; stylesheet1.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006"); stylesheet1.AddNamespaceDeclaration("x14ac", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac"); Fonts fonts1 = new Fonts() { Count = (UInt32Value)1U, KnownFonts = true }; Font font1 = new Font(); FontSize fontSize1 = new FontSize() { Val = 11D }; Color color1 = new Color() { Theme = (UInt32Value)1U }; FontName fontName1 = new FontName() { Val = "Calibri" }; FontFamilyNumbering fontFamilyNumbering1 = new FontFamilyNumbering() { Val = 2 }; FontScheme fontScheme1 = new FontScheme() { Val = FontSchemeValues.Minor }; font1.Append(fontSize1); font1.Append(color1); font1.Append(fontName1); font1.Append(fontFamilyNumbering1); font1.Append(fontScheme1); fonts1.Append(font1); Fills fills1 = new Fills() { Count = (UInt32Value)5U }; // FillId = 0 Fill fill1 = new Fill(); PatternFill patternFill1 = new PatternFill() { PatternType = PatternValues.None }; fill1.Append(patternFill1); // FillId = 1 Fill fill2 = new Fill(); PatternFill patternFill2 = new PatternFill() { PatternType = PatternValues.Gray125 }; fill2.Append(patternFill2); // FillId = 2,RED Fill fill3 = new Fill(); PatternFill patternFill3 = new PatternFill() { PatternType = PatternValues.Solid }; ForegroundColor foregroundColor1 = new ForegroundColor() { Rgb = "FFFF0000" }; BackgroundColor backgroundColor1 = new BackgroundColor() { Indexed = (UInt32Value)64U }; patternFill3.Append(foregroundColor1); patternFill3.Append(backgroundColor1); fill3.Append(patternFill3); // FillId = 3,BLUE Fill fill4 = new Fill(); PatternFill patternFill4 = new PatternFill() { PatternType = PatternValues.Solid }; ForegroundColor foregroundColor2 = new ForegroundColor() { Rgb = "FF0070C0" }; BackgroundColor backgroundColor2 = new BackgroundColor() { Indexed = (UInt32Value)64U }; patternFill4.Append(foregroundColor2); patternFill4.Append(backgroundColor2); fill4.Append(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 = (UInt32Value)64U }; patternFill5.Append(foregroundColor3); patternFill5.Append(backgroundColor3); fill5.Append(patternFill5); fills1.Append(fill1); fills1.Append(fill2); fills1.Append(fill3); fills1.Append(fill4); fills1.Append(fill5); Borders borders1 = new Borders() { Count = (UInt32Value)1U }; Border border1 = new Border(); LeftBorder leftBorder1 = new LeftBorder(); RightBorder rightBorder1 = new RightBorder(); TopBorder topBorder1 = new TopBorder(); BottomBorder bottomBorder1 = new BottomBorder(); DiagonalBorder diagonalBorder1 = new DiagonalBorder(); border1.Append(leftBorder1); border1.Append(rightBorder1); border1.Append(topBorder1); border1.Append(bottomBorder1); border1.Append(diagonalBorder1); borders1.Append(border1); CellStyleFormats cellStyleFormats1 = new CellStyleFormats() { Count = (UInt32Value)1U }; CellFormat cellFormat1 = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U }; cellStyleFormats1.Append(cellFormat1); CellFormats cellFormats1 = new CellFormats() { Count = (UInt32Value)4U }; CellFormat cellFormat2 = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U }; CellFormat cellFormat3 = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)2U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U, ApplyFill = true }; CellFormat cellFormat4 = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)3U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U, ApplyFill = true }; CellFormat cellFormat5 = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)4U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U, ApplyFill = true }; cellFormats1.Append(cellFormat2); cellFormats1.Append(cellFormat3); cellFormats1.Append(cellFormat4); cellFormats1.Append(cellFormat5); CellStyles cellStyles1 = new CellStyles() { Count = (UInt32Value)1U }; CellStyle cellStyle1 = new CellStyle() { Name = "Normal", FormatId = (UInt32Value)0U, BuiltinId = (UInt32Value)0U }; cellStyles1.Append(cellStyle1); DifferentialFormats differentialFormats1 = new DifferentialFormats() { Count = (UInt32Value)0U }; TableStyles tableStyles1 = new TableStyles() { Count = (UInt32Value)0U, DefaultTableStyle = "TableStyleMedium2", DefaultPivotStyle = "PivotStyleMedium9" }; StylesheetExtensionList stylesheetExtensionList1 = new StylesheetExtensionList(); StylesheetExtension stylesheetExtension1 = new StylesheetExtension() { Uri = "{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}" }; stylesheetExtension1.AddNamespaceDeclaration("x14", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"); stylesheetExtensionList1.Append(stylesheetExtension1); stylesheet1.Append(fonts1); stylesheet1.Append(fills1); stylesheet1.Append(borders1); stylesheet1.Append(cellStyleFormats1); stylesheet1.Append(cellFormats1); stylesheet1.Append(cellStyles1); stylesheet1.Append(differentialFormats1); stylesheet1.Append(tableStyles1); stylesheet1.Append(stylesheetExtensionList1); return(stylesheet1); }
private UInt32Value SetCellStyle(System.Drawing.Color fillColor, bool locked) { Fill fill = new Fill(); PatternFill patternFill = new PatternFill() { PatternType = PatternValues.Solid }; ForegroundColor foregroundColor1 = new ForegroundColor() { Rgb = System.Drawing.Color.FromArgb(fillColor.A, fillColor.R, fillColor.G, fillColor.B).Name }; BackgroundColor backgroundColor1 = new BackgroundColor() { Indexed = (UInt32Value)64U }; patternFill.Append(foregroundColor1); patternFill.Append(backgroundColor1); fill.Append(patternFill); ExcelStyleSheet.Fills.Count++; ExcelStyleSheet.Fills.Append(fill); CellFormat myCellFormat = new CellFormat { FontId = (UInt32Value)0U, FillId = (UInt32Value)ExcelStyleSheet.Fills.Count - 1, ApplyFill = true, NumberFormatId = (UInt32Value)0U, FormatId = (UInt32Value)0U, BorderId = (UInt32Value)1U, ApplyBorder = true, ApplyProtection = true }; Alignment alignment = new Alignment() { WrapText = true }; myCellFormat.Append(alignment); if (!locked) { Protection protection = new Protection() { Locked = false }; myCellFormat.Append(protection); } ExcelStyleSheet.CellFormats.Count++; ExcelStyleSheet.CellFormats.Append(myCellFormat); return (UInt32Value)ExcelStyleSheet.CellFormats.Count - 1; }
// создает ситили форматы private void GenWorkbookStylesPart(WorkbookStylesPart workbookStylesPart) { Stylesheet stylesheet = new Stylesheet(); Fonts fonts1 = new Fonts(); Font font1 = new Font(); fonts1.Append(font1); Fills fills1 = new Fills(); Fill fill1 = new Fill(); Fill fill2 = new Fill(); Fill fill3 = new Fill(); PatternFill patternFill3 = new PatternFill() { PatternType = PatternValues.Solid }; ForegroundColor foregroundColor1 = new ForegroundColor() { Rgb = "FFFFFF00" }; patternFill3.Append(foregroundColor1); fill3.Append(patternFill3); fills1.Append(fill1); fills1.Append(fill2); fills1.Append(fill3); Borders borders1 = new Borders(); Border border1 = new Border(); borders1.Append(border1); //Переопределяем номера формата 164U, 166U, 167U, 168U, NumberingFormats numberingFormats1 = new NumberingFormats() { Count = (UInt32Value)3U }; NumberingFormat numberingFormat1 = new NumberingFormat() { NumberFormatId = (UInt32Value)164U, FormatCode = "[$-F800]dddd\\,\\ mmmm\\ dd\\,\\ yyyy" }; NumberingFormat numberingFormat2 = new NumberingFormat() { NumberFormatId = (UInt32Value)166U, FormatCode = "#,##0.000\"р.\"" }; NumberingFormat numberingFormat3 = new NumberingFormat() { NumberFormatId = (UInt32Value)167U, FormatCode = "#,##0\"р.\"" }; //"#,##0.00\"р.\"" }; NumberingFormat numberingFormat4 = new NumberingFormat() { NumberFormatId = (UInt32Value)168U, FormatCode = "#,##0.00\"р.\"" }; numberingFormats1.Append(numberingFormat1); numberingFormats1.Append(numberingFormat2); numberingFormats1.Append(numberingFormat3); numberingFormats1.Append(numberingFormat4); CellFormats cellFormats1 = new CellFormats() { Count = (UInt32Value)6U }; CellFormat cellFormat2 = new CellFormat() { NumberFormatId = (UInt32Value)0U }; // Формат № 0 по умолчанию общий CellFormat cellFormat3 = new CellFormat() { NumberFormatId = (UInt32Value)164U }; // Формат № 1 для дат FormatCode = "[$-F800]dddd\\,\\ mmmm\\ dd\\,\\ yyyy" CellFormat cellFormat4 = new CellFormat() { NumberFormatId = (UInt32Value)166U }; //формат № 2 для денег по тысяч. ###,### <-- (number/ 1000) CellFormat cellFormat5 = new CellFormat() { NumberFormatId = (UInt32Value)14U }; //формат № 3 для дат * 14.03.2015 CellFormat cellFormat6 = new CellFormat() { NumberFormatId = (UInt32Value)2U }; //формат № 4 для чисел CellFormat cellFormat7 = new CellFormat() { NumberFormatId = (UInt32Value)1U }; //более подходящий формат № 5U для чисел (5U) CellFormat cellFormat8 = new CellFormat() { NumberFormatId = (UInt32Value)165U }; //формат №6U для денег по умолчанию CellFormat cellFormat9 = new CellFormat() { NumberFormatId = (UInt32Value)167U }; // формат №7U для денег(переопределенный) по три разряда ### ### р. CellFormat cellFormat10 = new CellFormat() { NumberFormatId = (UInt32Value)168U }; // формат №8U для денег(переопределенный) ### ###,00 р. cellFormats1.Append(cellFormat2); cellFormats1.Append(cellFormat3); cellFormats1.Append(cellFormat4); cellFormats1.Append(cellFormat5); cellFormats1.Append(cellFormat6); cellFormats1.Append(cellFormat7); cellFormats1.Append(cellFormat8); cellFormats1.Append(cellFormat9); cellFormats1.Append(cellFormat10); stylesheet.Append(numberingFormats1); stylesheet.Append(fonts1); stylesheet.Append(fills1); stylesheet.Append(borders1); stylesheet.Append(cellFormats1); workbookStylesPart.Stylesheet = stylesheet; }
// Generates content of workbookStyles. private void GenerateWorkbookStylesContent(WorkbookStylesPart workbookStyles) { Stylesheet stylesheet1 = new Stylesheet() { MCAttributes = new MarkupCompatibilityAttributes() { Ignorable = "x14ac" } }; stylesheet1.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006"); stylesheet1.AddNamespaceDeclaration("x14ac", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac"); NumberingFormats numberingFormats1 = new NumberingFormats() { Count = (UInt32Value)1U }; NumberingFormat numberingFormat1 = new NumberingFormat() { NumberFormatId = (UInt32Value)43U, FormatCode = "_(* #,##0.00_);_(* \\(#,##0.00\\);_(* \"-\"??_);_(@_)" }; numberingFormats1.Append(numberingFormat1); Fonts fonts1 = new Fonts() { Count = (UInt32Value)4U, KnownFonts = true }; Font font1 = new Font(); FontSize fontSize1 = new FontSize() { Val = 11D }; Color color1 = new Color() { Theme = (UInt32Value)1U }; FontName fontName1 = new FontName() { Val = "Calibri" }; FontFamilyNumbering fontFamilyNumbering1 = new FontFamilyNumbering() { Val = 2 }; FontScheme fontScheme1 = new FontScheme() { Val = FontSchemeValues.Minor }; font1.Append(fontSize1); font1.Append(color1); font1.Append(fontName1); font1.Append(fontFamilyNumbering1); font1.Append(fontScheme1); Font font2 = new Font(); Bold bold1 = new Bold(); FontSize fontSize2 = new FontSize() { Val = 11D }; Color color2 = new Color() { Theme = (UInt32Value)1U }; FontName fontName2 = new FontName() { Val = "Calibri" }; FontFamilyNumbering fontFamilyNumbering2 = new FontFamilyNumbering() { Val = 2 }; FontScheme fontScheme2 = new FontScheme() { Val = FontSchemeValues.Minor }; font2.Append(bold1); font2.Append(fontSize2); font2.Append(color2); font2.Append(fontName2); font2.Append(fontFamilyNumbering2); font2.Append(fontScheme2); Font font3 = new Font(); Bold bold2 = new Bold(); Italic italic1 = new Italic(); FontSize fontSize3 = new FontSize() { Val = 11D }; Color color3 = new Color() { Rgb = "FFFF0000" }; FontName fontName3 = new FontName() { Val = "Calibri" }; FontFamilyNumbering fontFamilyNumbering3 = new FontFamilyNumbering() { Val = 2 }; FontScheme fontScheme3 = new FontScheme() { Val = FontSchemeValues.Minor }; font3.Append(bold2); font3.Append(italic1); font3.Append(fontSize3); font3.Append(color3); font3.Append(fontName3); font3.Append(fontFamilyNumbering3); font3.Append(fontScheme3); Font font4 = new Font(); Italic italic2 = new Italic(); FontSize fontSize4 = new FontSize() { Val = 11D }; Color color4 = new Color() { Rgb = "FFFF0000" }; FontName fontName4 = new FontName() { Val = "Calibri" }; FontFamilyNumbering fontFamilyNumbering4 = new FontFamilyNumbering() { Val = 2 }; FontScheme fontScheme4 = new FontScheme() { Val = FontSchemeValues.Minor }; font4.Append(italic2); font4.Append(fontSize4); font4.Append(color4); font4.Append(fontName4); font4.Append(fontFamilyNumbering4); font4.Append(fontScheme4); fonts1.Append(font1); fonts1.Append(font2); fonts1.Append(font3); fonts1.Append(font4); Fills fills1 = new Fills() { Count = (UInt32Value)4U }; Fill fill1 = new Fill(); PatternFill patternFill1 = new PatternFill() { PatternType = PatternValues.None }; fill1.Append(patternFill1); Fill fill2 = new Fill(); PatternFill patternFill2 = new PatternFill() { PatternType = PatternValues.Gray125 }; fill2.Append(patternFill2); Fill fill3 = new Fill(); PatternFill patternFill3 = new PatternFill() { PatternType = PatternValues.Solid }; ForegroundColor foregroundColor1 = new ForegroundColor() { Theme = (UInt32Value)0U, Tint = -4.9989318521683403E-2D }; BackgroundColor backgroundColor1 = new BackgroundColor() { Indexed = (UInt32Value)64U }; patternFill3.Append(foregroundColor1); patternFill3.Append(backgroundColor1); fill3.Append(patternFill3); Fill fill4 = new Fill(); PatternFill patternFill4 = new PatternFill() { PatternType = PatternValues.Solid }; ForegroundColor foregroundColor2 = new ForegroundColor() { Rgb = "FFFFFFCC" }; BackgroundColor backgroundColor2 = new BackgroundColor() { Indexed = (UInt32Value)64U }; patternFill4.Append(foregroundColor2); patternFill4.Append(backgroundColor2); fill4.Append(patternFill4); fills1.Append(fill1); fills1.Append(fill2); fills1.Append(fill3); fills1.Append(fill4); Borders borders1 = new Borders() { Count = (UInt32Value)2U }; Border border1 = new Border(); LeftBorder leftBorder1 = new LeftBorder(); RightBorder rightBorder1 = new RightBorder(); TopBorder topBorder1 = new TopBorder(); BottomBorder bottomBorder1 = new BottomBorder(); DiagonalBorder diagonalBorder1 = new DiagonalBorder(); border1.Append(leftBorder1); border1.Append(rightBorder1); border1.Append(topBorder1); border1.Append(bottomBorder1); border1.Append(diagonalBorder1); Border border2 = new Border(); LeftBorder leftBorder2 = new LeftBorder(); RightBorder rightBorder2 = new RightBorder(); TopBorder topBorder2 = new TopBorder() { Style = BorderStyleValues.Thin }; Color color5 = new Color() { Indexed = (UInt32Value)64U }; topBorder2.Append(color5); BottomBorder bottomBorder2 = new BottomBorder(); DiagonalBorder diagonalBorder2 = new DiagonalBorder(); border2.Append(leftBorder2); border2.Append(rightBorder2); border2.Append(topBorder2); border2.Append(bottomBorder2); border2.Append(diagonalBorder2); borders1.Append(border1); borders1.Append(border2); CellStyleFormats cellStyleFormats1 = new CellStyleFormats() { Count = (UInt32Value)1U }; CellFormat cellFormat1 = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U }; cellStyleFormats1.Append(cellFormat1); CellFormats cellFormats1 = new CellFormats() { Count = (UInt32Value)16U }; CellFormat cellFormat2 = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U }; CellFormat cellFormat3 = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)2U, FillId = (UInt32Value)2U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U, ApplyFont = true, ApplyFill = true, ApplyAlignment = true }; Alignment alignment1 = new Alignment() { Horizontal = HorizontalAlignmentValues.Center }; cellFormat3.Append(alignment1); CellFormat cellFormat4 = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)2U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U, ApplyFill = true }; CellFormat cellFormat5 = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)1U, FillId = (UInt32Value)3U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U, ApplyFont = true, ApplyFill = true, ApplyAlignment = true }; Alignment alignment2 = new Alignment() { Horizontal = HorizontalAlignmentValues.Left }; cellFormat5.Append(alignment2); CellFormat cellFormat6 = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)1U, FillId = (UInt32Value)3U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U, ApplyFont = true, ApplyFill = true, ApplyAlignment = true }; Alignment alignment3 = new Alignment() { Horizontal = HorizontalAlignmentValues.Center }; cellFormat6.Append(alignment3); CellFormat cellFormat7 = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)2U, FillId = (UInt32Value)2U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U, ApplyFont = true, ApplyFill = true, ApplyAlignment = true }; Alignment alignment4 = new Alignment() { Horizontal = HorizontalAlignmentValues.Center }; cellFormat7.Append(alignment4); CellFormat cellFormat8 = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)2U, FillId = (UInt32Value)2U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U, ApplyFont = true, ApplyFill = true, ApplyAlignment = true }; Alignment alignment5 = new Alignment() { Horizontal = HorizontalAlignmentValues.Right }; cellFormat8.Append(alignment5); CellFormat cellFormat9 = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)3U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U, ApplyFill = true, ApplyAlignment = true }; Alignment alignment6 = new Alignment() { Horizontal = HorizontalAlignmentValues.Left }; cellFormat9.Append(alignment6); CellFormat cellFormat10 = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)3U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U, ApplyFill = true, ApplyAlignment = true }; Alignment alignment7 = new Alignment() { Horizontal = HorizontalAlignmentValues.Center }; cellFormat10.Append(alignment7); CellFormat cellFormat11 = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)3U, FillId = (UInt32Value)2U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U, ApplyFont = true, ApplyFill = true, ApplyAlignment = true }; Alignment alignment8 = new Alignment() { Horizontal = HorizontalAlignmentValues.Center }; cellFormat11.Append(alignment8); CellFormat cellFormat12 = new CellFormat() { NumberFormatId = (UInt32Value)43U, FontId = (UInt32Value)2U, FillId = (UInt32Value)2U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U, ApplyNumberFormat = true, ApplyFont = true, ApplyFill = true }; CellFormat cellFormat13 = new CellFormat() { NumberFormatId = (UInt32Value)9U, FontId = (UInt32Value)0U, FillId = (UInt32Value)3U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U, ApplyNumberFormat = true, ApplyFill = true, ApplyAlignment = true }; Alignment alignment9 = new Alignment() { Horizontal = HorizontalAlignmentValues.Left }; cellFormat13.Append(alignment9); CellFormat cellFormat14 = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)2U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U, ApplyFill = true, ApplyAlignment = true }; Alignment alignment10 = new Alignment() { Horizontal = HorizontalAlignmentValues.Center }; cellFormat14.Append(alignment10); CellFormat cellFormat15 = new CellFormat() { NumberFormatId = (UInt32Value)37U, FontId = (UInt32Value)2U, FillId = (UInt32Value)2U, BorderId = (UInt32Value)1U, FormatId = (UInt32Value)0U, ApplyNumberFormat = true, ApplyFont = true, ApplyFill = true, ApplyBorder = true, ApplyAlignment = true }; Alignment alignment11 = new Alignment() { Horizontal = HorizontalAlignmentValues.Center }; cellFormat15.Append(alignment11); CellFormat cellFormat16 = new CellFormat() { NumberFormatId = (UInt32Value)43U, FontId = (UInt32Value)2U, FillId = (UInt32Value)2U, BorderId = (UInt32Value)1U, FormatId = (UInt32Value)0U, ApplyNumberFormat = true, ApplyFont = true, ApplyFill = true, ApplyBorder = true }; CellFormat cellFormat17 = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)2U, FillId = (UInt32Value)2U, BorderId = (UInt32Value)1U, FormatId = (UInt32Value)0U, ApplyFont = true, ApplyFill = true, ApplyBorder = true }; cellFormats1.Append(cellFormat2); cellFormats1.Append(cellFormat3); cellFormats1.Append(cellFormat4); cellFormats1.Append(cellFormat5); cellFormats1.Append(cellFormat6); cellFormats1.Append(cellFormat7); cellFormats1.Append(cellFormat8); cellFormats1.Append(cellFormat9); cellFormats1.Append(cellFormat10); cellFormats1.Append(cellFormat11); cellFormats1.Append(cellFormat12); cellFormats1.Append(cellFormat13); cellFormats1.Append(cellFormat14); cellFormats1.Append(cellFormat15); cellFormats1.Append(cellFormat16); cellFormats1.Append(cellFormat17); CellStyles cellStyles1 = new CellStyles() { Count = (UInt32Value)1U }; CellStyle cellStyle1 = new CellStyle() { Name = "Normal", FormatId = (UInt32Value)0U, BuiltinId = (UInt32Value)0U }; cellStyles1.Append(cellStyle1); DifferentialFormats differentialFormats1 = new DifferentialFormats() { Count = (UInt32Value)0U }; TableStyles tableStyles1 = new TableStyles() { Count = (UInt32Value)0U, DefaultTableStyle = "TableStyleMedium2", DefaultPivotStyle = "PivotStyleLight16" }; StylesheetExtensionList stylesheetExtensionList1 = new StylesheetExtensionList(); StylesheetExtension stylesheetExtension1 = new StylesheetExtension() { Uri = "{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}" }; stylesheetExtension1.AddNamespaceDeclaration("x14", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"); DocumentFormat.OpenXml.Office2010.Excel.SlicerStyles slicerStyles1 = new DocumentFormat.OpenXml.Office2010.Excel.SlicerStyles() { DefaultSlicerStyle = "SlicerStyleLight1" }; stylesheetExtension1.Append(slicerStyles1); //StylesheetExtension stylesheetExtension2 = new StylesheetExtension(){ Uri = "{9260A510-F301-46a8-8635-F512D64BE5F5}" }; //stylesheetExtension2.AddNamespaceDeclaration("x15", "http://schemas.microsoft.com/office/spreadsheetml/2010/11/main"); //X15.TimelineStyles timelineStyles1 = new X15.TimelineStyles(){ DefaultTimelineStyle = "TimeSlicerStyleLight1" }; //stylesheetExtension2.Append(timelineStyles1); stylesheetExtensionList1.Append(stylesheetExtension1); //stylesheetExtensionList1.Append(stylesheetExtension2); stylesheet1.Append(numberingFormats1); stylesheet1.Append(fonts1); stylesheet1.Append(fills1); stylesheet1.Append(borders1); stylesheet1.Append(cellStyleFormats1); stylesheet1.Append(cellFormats1); stylesheet1.Append(cellStyles1); stylesheet1.Append(differentialFormats1); stylesheet1.Append(tableStyles1); stylesheet1.Append(stylesheetExtensionList1); workbookStyles.Stylesheet = stylesheet1; }
private static void GenerateWorkbookStylesPartContent(WorkbookStylesPart workbookStylesPart1) { Stylesheet stylesheet1 = new Stylesheet() { MCAttributes = new MarkupCompatibilityAttributes() { Ignorable = "x14ac" } }; stylesheet1.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006"); stylesheet1.AddNamespaceDeclaration("x14ac", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac"); Fonts fonts1 = new Fonts() { Count = (UInt32Value)2U, KnownFonts = true }; Font font1 = new Font(); FontSize fontSize1 = new FontSize() { Val = 11D }; Color color1 = new Color() { Theme = (UInt32Value)1U }; FontName fontName1 = new FontName() { Val = "Calibri" }; FontFamilyNumbering fontFamilyNumbering1 = new FontFamilyNumbering() { Val = 2 }; FontScheme fontScheme1 = new FontScheme() { Val = FontSchemeValues.Minor }; font1.Append(fontSize1); font1.Append(color1); font1.Append(fontName1); font1.Append(fontFamilyNumbering1); font1.Append(fontScheme1); Font font2 = new Font(); Bold bold1 = new Bold(); FontSize fontSize2 = new FontSize() { Val = 11D }; Color color2 = new Color() { Theme = (UInt32Value)1U }; FontName fontName2 = new FontName() { Val = "Calibri" }; FontFamilyNumbering fontFamilyNumbering2 = new FontFamilyNumbering() { Val = 2 }; FontScheme fontScheme2 = new FontScheme() { Val = FontSchemeValues.Minor }; font2.Append(bold1); font2.Append(fontSize2); font2.Append(color2); font2.Append(fontName2); font2.Append(fontFamilyNumbering2); font2.Append(fontScheme2); fonts1.Append(font1); fonts1.Append(font2); Fills fills1 = new Fills() { Count = (UInt32Value)2U }; Fill fill1 = new Fill(); PatternFill patternFill1 = new PatternFill() { PatternType = PatternValues.None }; fill1.Append(patternFill1); Fill fill2 = new Fill(); PatternFill patternFill2 = new PatternFill() { PatternType = PatternValues.Gray125 }; fill2.Append(patternFill2); fills1.Append(fill1); fills1.Append(fill2); Borders borders1 = new Borders() { Count = (UInt32Value)2U }; Border border1 = new Border(); LeftBorder leftBorder1 = new LeftBorder(); RightBorder rightBorder1 = new RightBorder(); TopBorder topBorder1 = new TopBorder(); BottomBorder bottomBorder1 = new BottomBorder(); DiagonalBorder diagonalBorder1 = new DiagonalBorder(); border1.Append(leftBorder1); border1.Append(rightBorder1); border1.Append(topBorder1); border1.Append(bottomBorder1); border1.Append(diagonalBorder1); Border border2 = new Border(); LeftBorder leftBorder2 = new LeftBorder() { Style = BorderStyleValues.Thin }; Color color3 = new Color() { Indexed = (UInt32Value)64U }; leftBorder2.Append(color3); RightBorder rightBorder2 = new RightBorder() { Style = BorderStyleValues.Thin }; Color color4 = new Color() { Indexed = (UInt32Value)64U }; rightBorder2.Append(color4); TopBorder topBorder2 = new TopBorder() { Style = BorderStyleValues.Thin }; Color color5 = new Color() { Indexed = (UInt32Value)64U }; topBorder2.Append(color5); BottomBorder bottomBorder2 = new BottomBorder() { Style = BorderStyleValues.Thin }; Color color6 = new Color() { Indexed = (UInt32Value)64U }; bottomBorder2.Append(color6); DiagonalBorder diagonalBorder2 = new DiagonalBorder(); border2.Append(leftBorder2); border2.Append(rightBorder2); border2.Append(topBorder2); border2.Append(bottomBorder2); border2.Append(diagonalBorder2); borders1.Append(border1); borders1.Append(border2); CellStyleFormats cellStyleFormats1 = new CellStyleFormats() { Count = (UInt32Value)1U }; CellFormat cellFormat1 = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U }; cellStyleFormats1.Append(cellFormat1); CellFormats cellFormats1 = new CellFormats() { Count = (UInt32Value)3U }; CellFormat cellFormat2 = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U }; CellFormat cellFormat3 = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)1U, FormatId = (UInt32Value)0U, ApplyBorder = true }; CellFormat cellFormat4 = new CellFormat() { NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)1U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)1U, FormatId = (UInt32Value)0U, ApplyFont = true, ApplyBorder = true }; cellFormats1.Append(cellFormat2); cellFormats1.Append(cellFormat3); cellFormats1.Append(cellFormat4); CellStyles cellStyles1 = new CellStyles() { Count = (UInt32Value)1U }; CellStyle cellStyle1 = new CellStyle() { Name = "Normal", FormatId = (UInt32Value)0U, BuiltinId = (UInt32Value)0U }; cellStyles1.Append(cellStyle1); DifferentialFormats differentialFormats1 = new DifferentialFormats() { Count = (UInt32Value)0U }; TableStyles tableStyles1 = new TableStyles() { Count = (UInt32Value)0U, DefaultTableStyle = "TableStyleMedium2", DefaultPivotStyle = "PivotStyleLight16" }; StylesheetExtensionList stylesheetExtensionList1 = new StylesheetExtensionList(); StylesheetExtension stylesheetExtension1 = new StylesheetExtension() { Uri = "{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}" }; stylesheetExtension1.AddNamespaceDeclaration("x14", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"); X14.SlicerStyles slicerStyles1 = new X14.SlicerStyles() { DefaultSlicerStyle = "SlicerStyleLight1" }; stylesheetExtension1.Append(slicerStyles1); StylesheetExtension stylesheetExtension2 = new StylesheetExtension() { Uri = "{9260A510-F301-46a8-8635-F512D64BE5F5}" }; stylesheetExtension2.AddNamespaceDeclaration("x15", "http://schemas.microsoft.com/office/spreadsheetml/2010/11/main"); X15.TimelineStyles timelineStyles1 = new X15.TimelineStyles() { DefaultTimelineStyle = "TimeSlicerStyleLight1" }; stylesheetExtension2.Append(timelineStyles1); stylesheetExtensionList1.Append(stylesheetExtension1); stylesheetExtensionList1.Append(stylesheetExtension2); stylesheet1.Append(fonts1); stylesheet1.Append(fills1); stylesheet1.Append(borders1); stylesheet1.Append(cellStyleFormats1); stylesheet1.Append(cellFormats1); stylesheet1.Append(cellStyles1); stylesheet1.Append(differentialFormats1); stylesheet1.Append(tableStyles1); stylesheet1.Append(stylesheetExtensionList1); workbookStylesPart1.Stylesheet = stylesheet1; }
private static Stylesheet SetDefault() { //Fonts var fonts = new Fonts(); var font0 = new Font(); var fontSize0 = new FontSize { Val = 10 }; font0.AppendChild(fontSize0); var font1 = new Font(); var fontSize1 = new FontSize { Val = 12 }; var fontBold1 = new Bold(); var fontColor1 = new Color { Rgb = "FFFFFF" }; font1.AppendChild(fontSize1); font1.AppendChild(fontBold1); font1.AppendChild(fontColor1); fonts.AppendChild(font0); fonts.AppendChild(font1); // Alignments var alignmentCenter = new Alignment(); alignmentCenter.Horizontal = HorizontalAlignmentValues.Center; //Fill var fills = new Fills(); var fill0 = new Fill(); var patternFill0 = new PatternFill { PatternType = PatternValues.None }; fill0.Append(patternFill0); var fillSkip = new Fill(); // Not valid needs to skip var patternFillSkip = new PatternFill { PatternType = PatternValues.None }; fillSkip.Append(patternFillSkip); var fill1 = new Fill(); var patternFill1 = new PatternFill { PatternType = PatternValues.Solid }; var foregroundColor1 = new ForegroundColor { Rgb = "00000000" }; var backgroundColor1 = new BackgroundColor { Indexed = 64U }; patternFill1.Append(foregroundColor1); patternFill1.Append(backgroundColor1); fill1.Append(patternFill1); fills.Append(fill0); fills.Append(fillSkip); fills.Append(fill1); //Border var borders = new Borders(); var border0 = new Border(); var border1 = new Border(); borders.AppendChild(border0); borders.AppendChild(border1); var cellFormats = new CellFormats( new CellFormat { FontId = 0, FillId = 0, BorderId = 0, ApplyFill = true }, // Index 0 new CellFormat { FontId = 1, FillId = 2, BorderId = 1, ApplyFill = true, Alignment = alignmentCenter } // Index 1 ); return(new Stylesheet(fonts, fills, borders, cellFormats)); }
public static void AddStylesToWorkbookPart(WorkbookPart part) { var workbookStylesPart = part.AddNewPart <WorkbookStylesPart>("WorkbookStyles"); var stylesheet1 = new Stylesheet { MCAttributes = new MarkupCompatibilityAttributes { Ignorable = "x14ac" } }; stylesheet1.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006"); stylesheet1.AddNamespaceDeclaration("x14ac", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac"); var fonts1 = new Fonts { Count = 1U, KnownFonts = true }; var font1 = new Font(); var fontSize1 = new FontSize { Val = 11D }; var color1 = new Color { Theme = 1U }; var fontName1 = new FontName { Val = "Calibri" }; var fontFamilyNumbering1 = new FontFamilyNumbering { Val = 2 }; var fontScheme1 = new FontScheme { Val = FontSchemeValues.Minor }; font1.Append(fontSize1); font1.Append(color1); font1.Append(fontName1); font1.Append(fontFamilyNumbering1); font1.Append(fontScheme1); fonts1.Append(font1); var fills1 = new Fills { Count = 2U }; var fill1 = new Fill(); var patternFill1 = new PatternFill { PatternType = PatternValues.None }; fill1.Append(patternFill1); var fill2 = new Fill(); var patternFill2 = new PatternFill { PatternType = PatternValues.Gray125 }; fill2.Append(patternFill2); fills1.Append(fill1); fills1.Append(fill2); var borders1 = new Borders { Count = 1U }; var border1 = new Border(); var leftBorder1 = new LeftBorder(); var rightBorder1 = new RightBorder(); var topBorder1 = new TopBorder(); var bottomBorder1 = new BottomBorder(); var diagonalBorder1 = new DiagonalBorder(); border1.Append(leftBorder1); border1.Append(rightBorder1); border1.Append(topBorder1); border1.Append(bottomBorder1); border1.Append(diagonalBorder1); borders1.Append(border1); var cellStyleFormats1 = new CellStyleFormats { Count = 1U }; var cellStyleFormat = new CellFormat { NumberFormatId = 0U, FontId = 0U, FillId = 0U, BorderId = 0U }; cellStyleFormats1.Append(cellStyleFormat); var cellFormats = new CellFormats { Count = 2U }; // index 0 (default) => unlocked var cellFormat0 = new CellFormat { NumberFormatId = 0U, FontId = 0U, FillId = 0U, BorderId = 0U, FormatId = 0U, ApplyProtection = true }.AppendItem(new Protection { Locked = false }); // index 1 => locked var cellFormat1 = new CellFormat { NumberFormatId = 0U, FontId = 0U, FillId = 0U, BorderId = 0U, FormatId = 0U }; cellFormats.Append(cellFormat0); cellFormats.Append(cellFormat1); var cellStyles1 = new CellStyles { Count = 1U }; var cellStyle1 = new CellStyle { Name = "Normal", FormatId = 0U, BuiltinId = 0U }; cellStyles1.Append(cellStyle1); stylesheet1.Append(fonts1); stylesheet1.Append(fills1); stylesheet1.Append(borders1); stylesheet1.Append(cellStyleFormats1); stylesheet1.Append(cellFormats); stylesheet1.Append(cellStyles1); workbookStylesPart.Stylesheet = stylesheet1; }
// Generates content of workbookStyles. private void GenerateWorkbookStylesContent(WorkbookStylesPart workbookStyles) { Stylesheet stylesheet1 = new Stylesheet(){ MCAttributes = new MarkupCompatibilityAttributes(){ Ignorable = "x14ac" } }; stylesheet1.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006"); stylesheet1.AddNamespaceDeclaration("x14ac", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac"); NumberingFormats numberingFormats1 = new NumberingFormats(){ Count = (UInt32Value)1U }; NumberingFormat numberingFormat1 = new NumberingFormat(){ NumberFormatId = (UInt32Value)43U, FormatCode = "_(* #,##0.00_);_(* \\(#,##0.00\\);_(* \"-\"??_);_(@_)" }; numberingFormats1.Append(numberingFormat1); Fonts fonts1 = new Fonts(){ Count = (UInt32Value)4U, KnownFonts = true }; Font font1 = new Font(); FontSize fontSize1 = new FontSize(){ Val = 11D }; Color color1 = new Color(){ Theme = (UInt32Value)1U }; FontName fontName1 = new FontName(){ Val = "Calibri" }; FontFamilyNumbering fontFamilyNumbering1 = new FontFamilyNumbering(){ Val = 2 }; FontScheme fontScheme1 = new FontScheme(){ Val = FontSchemeValues.Minor }; font1.Append(fontSize1); font1.Append(color1); font1.Append(fontName1); font1.Append(fontFamilyNumbering1); font1.Append(fontScheme1); Font font2 = new Font(); Bold bold1 = new Bold(); FontSize fontSize2 = new FontSize(){ Val = 11D }; Color color2 = new Color(){ Theme = (UInt32Value)1U }; FontName fontName2 = new FontName(){ Val = "Calibri" }; FontFamilyNumbering fontFamilyNumbering2 = new FontFamilyNumbering(){ Val = 2 }; FontScheme fontScheme2 = new FontScheme(){ Val = FontSchemeValues.Minor }; font2.Append(bold1); font2.Append(fontSize2); font2.Append(color2); font2.Append(fontName2); font2.Append(fontFamilyNumbering2); font2.Append(fontScheme2); Font font3 = new Font(); Bold bold2 = new Bold(); Italic italic1 = new Italic(); FontSize fontSize3 = new FontSize(){ Val = 11D }; Color color3 = new Color(){ Rgb = "FFFF0000" }; FontName fontName3 = new FontName(){ Val = "Calibri" }; FontFamilyNumbering fontFamilyNumbering3 = new FontFamilyNumbering(){ Val = 2 }; FontScheme fontScheme3 = new FontScheme(){ Val = FontSchemeValues.Minor }; font3.Append(bold2); font3.Append(italic1); font3.Append(fontSize3); font3.Append(color3); font3.Append(fontName3); font3.Append(fontFamilyNumbering3); font3.Append(fontScheme3); Font font4 = new Font(); Italic italic2 = new Italic(); FontSize fontSize4 = new FontSize(){ Val = 11D }; Color color4 = new Color(){ Rgb = "FFFF0000" }; FontName fontName4 = new FontName(){ Val = "Calibri" }; FontFamilyNumbering fontFamilyNumbering4 = new FontFamilyNumbering(){ Val = 2 }; FontScheme fontScheme4 = new FontScheme(){ Val = FontSchemeValues.Minor }; font4.Append(italic2); font4.Append(fontSize4); font4.Append(color4); font4.Append(fontName4); font4.Append(fontFamilyNumbering4); font4.Append(fontScheme4); fonts1.Append(font1); fonts1.Append(font2); fonts1.Append(font3); fonts1.Append(font4); Fills fills1 = new Fills(){ Count = (UInt32Value)4U }; Fill fill1 = new Fill(); PatternFill patternFill1 = new PatternFill(){ PatternType = PatternValues.None }; fill1.Append(patternFill1); Fill fill2 = new Fill(); PatternFill patternFill2 = new PatternFill(){ PatternType = PatternValues.Gray125 }; fill2.Append(patternFill2); Fill fill3 = new Fill(); PatternFill patternFill3 = new PatternFill(){ PatternType = PatternValues.Solid }; ForegroundColor foregroundColor1 = new ForegroundColor(){ Theme = (UInt32Value)0U, Tint = -4.9989318521683403E-2D }; BackgroundColor backgroundColor1 = new BackgroundColor(){ Indexed = (UInt32Value)64U }; patternFill3.Append(foregroundColor1); patternFill3.Append(backgroundColor1); fill3.Append(patternFill3); Fill fill4 = new Fill(); PatternFill patternFill4 = new PatternFill(){ PatternType = PatternValues.Solid }; ForegroundColor foregroundColor2 = new ForegroundColor(){ Rgb = "FFFFFFCC" }; BackgroundColor backgroundColor2 = new BackgroundColor(){ Indexed = (UInt32Value)64U }; patternFill4.Append(foregroundColor2); patternFill4.Append(backgroundColor2); fill4.Append(patternFill4); fills1.Append(fill1); fills1.Append(fill2); fills1.Append(fill3); fills1.Append(fill4); Borders borders1 = new Borders(){ Count = (UInt32Value)2U }; Border border1 = new Border(); LeftBorder leftBorder1 = new LeftBorder(); RightBorder rightBorder1 = new RightBorder(); TopBorder topBorder1 = new TopBorder(); BottomBorder bottomBorder1 = new BottomBorder(); DiagonalBorder diagonalBorder1 = new DiagonalBorder(); border1.Append(leftBorder1); border1.Append(rightBorder1); border1.Append(topBorder1); border1.Append(bottomBorder1); border1.Append(diagonalBorder1); Border border2 = new Border(); LeftBorder leftBorder2 = new LeftBorder(); RightBorder rightBorder2 = new RightBorder(); TopBorder topBorder2 = new TopBorder(){ Style = BorderStyleValues.Thin }; Color color5 = new Color(){ Indexed = (UInt32Value)64U }; topBorder2.Append(color5); BottomBorder bottomBorder2 = new BottomBorder(); DiagonalBorder diagonalBorder2 = new DiagonalBorder(); border2.Append(leftBorder2); border2.Append(rightBorder2); border2.Append(topBorder2); border2.Append(bottomBorder2); border2.Append(diagonalBorder2); borders1.Append(border1); borders1.Append(border2); CellStyleFormats cellStyleFormats1 = new CellStyleFormats(){ Count = (UInt32Value)1U }; CellFormat cellFormat1 = new CellFormat(){ NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U }; cellStyleFormats1.Append(cellFormat1); CellFormats cellFormats1 = new CellFormats(){ Count = (UInt32Value)16U }; CellFormat cellFormat2 = new CellFormat(){ NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)0U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U }; CellFormat cellFormat3 = new CellFormat(){ NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)2U, FillId = (UInt32Value)2U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U, ApplyFont = true, ApplyFill = true, ApplyAlignment = true }; Alignment alignment1 = new Alignment(){ Horizontal = HorizontalAlignmentValues.Center }; cellFormat3.Append(alignment1); CellFormat cellFormat4 = new CellFormat(){ NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)2U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U, ApplyFill = true }; CellFormat cellFormat5 = new CellFormat(){ NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)1U, FillId = (UInt32Value)3U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U, ApplyFont = true, ApplyFill = true, ApplyAlignment = true }; Alignment alignment2 = new Alignment(){ Horizontal = HorizontalAlignmentValues.Left }; cellFormat5.Append(alignment2); CellFormat cellFormat6 = new CellFormat(){ NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)1U, FillId = (UInt32Value)3U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U, ApplyFont = true, ApplyFill = true, ApplyAlignment = true }; Alignment alignment3 = new Alignment(){ Horizontal = HorizontalAlignmentValues.Center }; cellFormat6.Append(alignment3); CellFormat cellFormat7 = new CellFormat(){ NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)2U, FillId = (UInt32Value)2U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U, ApplyFont = true, ApplyFill = true, ApplyAlignment = true }; Alignment alignment4 = new Alignment(){ Horizontal = HorizontalAlignmentValues.Center }; cellFormat7.Append(alignment4); CellFormat cellFormat8 = new CellFormat(){ NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)2U, FillId = (UInt32Value)2U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U, ApplyFont = true, ApplyFill = true, ApplyAlignment = true }; Alignment alignment5 = new Alignment(){ Horizontal = HorizontalAlignmentValues.Right }; cellFormat8.Append(alignment5); CellFormat cellFormat9 = new CellFormat(){ NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)3U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U, ApplyFill = true, ApplyAlignment = true }; Alignment alignment6 = new Alignment(){ Horizontal = HorizontalAlignmentValues.Left }; cellFormat9.Append(alignment6); CellFormat cellFormat10 = new CellFormat(){ NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)3U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U, ApplyFill = true, ApplyAlignment = true }; Alignment alignment7 = new Alignment(){ Horizontal = HorizontalAlignmentValues.Center }; cellFormat10.Append(alignment7); CellFormat cellFormat11 = new CellFormat(){ NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)3U, FillId = (UInt32Value)2U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U, ApplyFont = true, ApplyFill = true, ApplyAlignment = true }; Alignment alignment8 = new Alignment(){ Horizontal = HorizontalAlignmentValues.Center }; cellFormat11.Append(alignment8); CellFormat cellFormat12 = new CellFormat(){ NumberFormatId = (UInt32Value)43U, FontId = (UInt32Value)2U, FillId = (UInt32Value)2U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U, ApplyNumberFormat = true, ApplyFont = true, ApplyFill = true }; CellFormat cellFormat13 = new CellFormat(){ NumberFormatId = (UInt32Value)9U, FontId = (UInt32Value)0U, FillId = (UInt32Value)3U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U, ApplyNumberFormat = true, ApplyFill = true, ApplyAlignment = true }; Alignment alignment9 = new Alignment(){ Horizontal = HorizontalAlignmentValues.Left }; cellFormat13.Append(alignment9); CellFormat cellFormat14 = new CellFormat(){ NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)0U, FillId = (UInt32Value)2U, BorderId = (UInt32Value)0U, FormatId = (UInt32Value)0U, ApplyFill = true, ApplyAlignment = true }; Alignment alignment10 = new Alignment(){ Horizontal = HorizontalAlignmentValues.Center }; cellFormat14.Append(alignment10); CellFormat cellFormat15 = new CellFormat(){ NumberFormatId = (UInt32Value)37U, FontId = (UInt32Value)2U, FillId = (UInt32Value)2U, BorderId = (UInt32Value)1U, FormatId = (UInt32Value)0U, ApplyNumberFormat = true, ApplyFont = true, ApplyFill = true, ApplyBorder = true, ApplyAlignment = true }; Alignment alignment11 = new Alignment(){ Horizontal = HorizontalAlignmentValues.Center }; cellFormat15.Append(alignment11); CellFormat cellFormat16 = new CellFormat(){ NumberFormatId = (UInt32Value)43U, FontId = (UInt32Value)2U, FillId = (UInt32Value)2U, BorderId = (UInt32Value)1U, FormatId = (UInt32Value)0U, ApplyNumberFormat = true, ApplyFont = true, ApplyFill = true, ApplyBorder = true }; CellFormat cellFormat17 = new CellFormat(){ NumberFormatId = (UInt32Value)0U, FontId = (UInt32Value)2U, FillId = (UInt32Value)2U, BorderId = (UInt32Value)1U, FormatId = (UInt32Value)0U, ApplyFont = true, ApplyFill = true, ApplyBorder = true }; cellFormats1.Append(cellFormat2); cellFormats1.Append(cellFormat3); cellFormats1.Append(cellFormat4); cellFormats1.Append(cellFormat5); cellFormats1.Append(cellFormat6); cellFormats1.Append(cellFormat7); cellFormats1.Append(cellFormat8); cellFormats1.Append(cellFormat9); cellFormats1.Append(cellFormat10); cellFormats1.Append(cellFormat11); cellFormats1.Append(cellFormat12); cellFormats1.Append(cellFormat13); cellFormats1.Append(cellFormat14); cellFormats1.Append(cellFormat15); cellFormats1.Append(cellFormat16); cellFormats1.Append(cellFormat17); CellStyles cellStyles1 = new CellStyles(){ Count = (UInt32Value)1U }; CellStyle cellStyle1 = new CellStyle(){ Name = "Normal", FormatId = (UInt32Value)0U, BuiltinId = (UInt32Value)0U }; cellStyles1.Append(cellStyle1); DifferentialFormats differentialFormats1 = new DifferentialFormats(){ Count = (UInt32Value)0U }; TableStyles tableStyles1 = new TableStyles(){ Count = (UInt32Value)0U, DefaultTableStyle = "TableStyleMedium2", DefaultPivotStyle = "PivotStyleLight16" }; StylesheetExtensionList stylesheetExtensionList1 = new StylesheetExtensionList(); StylesheetExtension stylesheetExtension1 = new StylesheetExtension(){ Uri = "{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}" }; stylesheetExtension1.AddNamespaceDeclaration("x14", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"); DocumentFormat.OpenXml.Office2010.Excel.SlicerStyles slicerStyles1 = new DocumentFormat.OpenXml.Office2010.Excel.SlicerStyles(){ DefaultSlicerStyle = "SlicerStyleLight1" }; stylesheetExtension1.Append(slicerStyles1); //StylesheetExtension stylesheetExtension2 = new StylesheetExtension(){ Uri = "{9260A510-F301-46a8-8635-F512D64BE5F5}" }; //stylesheetExtension2.AddNamespaceDeclaration("x15", "http://schemas.microsoft.com/office/spreadsheetml/2010/11/main"); //X15.TimelineStyles timelineStyles1 = new X15.TimelineStyles(){ DefaultTimelineStyle = "TimeSlicerStyleLight1" }; //stylesheetExtension2.Append(timelineStyles1); stylesheetExtensionList1.Append(stylesheetExtension1); //stylesheetExtensionList1.Append(stylesheetExtension2); stylesheet1.Append(numberingFormats1); stylesheet1.Append(fonts1); stylesheet1.Append(fills1); stylesheet1.Append(borders1); stylesheet1.Append(cellStyleFormats1); stylesheet1.Append(cellFormats1); stylesheet1.Append(cellStyles1); stylesheet1.Append(differentialFormats1); stylesheet1.Append(tableStyles1); stylesheet1.Append(stylesheetExtensionList1); workbookStyles.Stylesheet = stylesheet1; }