internal void FromSpreadsheetColor(DocumentFormat.OpenXml.Spreadsheet.Color clr) { SetAllNull(); if (clr.Auto != null) { Auto = clr.Auto.Value; } if (clr.Indexed != null) { Indexed = clr.Indexed.Value; } if (clr.Rgb != null) { Rgb = clr.Rgb.Value; } if (clr.Theme != null) { Theme = clr.Theme.Value; } if (clr.Tint != null) { Tint = clr.Tint.Value; } SetDisplayColor(); }
internal DocumentFormat.OpenXml.Spreadsheet.Color ToSpreadsheetColor() { var clr = new DocumentFormat.OpenXml.Spreadsheet.Color(); if (Auto != null) { clr.Auto = Auto.Value; } if (Indexed != null) { clr.Indexed = Indexed.Value; } if (Rgb != null) { clr.Rgb = new HexBinaryValue(Rgb); } if (Theme != null) { clr.Theme = Theme.Value; } if ((Tint != null) && (Tint.Value != 0.0)) { clr.Tint = Tint.Value; } return(clr); }
/// <summary> /// Creates a new font and appends it to the workbook's stylesheet /// </summary> /// <param name="styleSheet">The stylesheet for the current WorkBook</param> /// <param name="fontName">The font name.</param> /// <param name="fontSize">The font size.</param> /// <param name="isBold">Set to true for bold font.</param> /// <param name="foreColor">The font color.</param> /// <returns>The index of the font.</returns> public static UInt32Value CreateFont( Stylesheet styleSheet, string fontName, double?fontSize, bool isBold, Color foreColor) { // Fonts fonts = styleSheet.GetFirstChild<Fonts>(); var font = new Font( ); if (!string.IsNullOrEmpty(fontName)) { var name = new FontName { Val = fontName }; font.Append(name); } if (fontSize.HasValue) { var size = new FontSize { Val = fontSize.Value }; font.Append(size); } if (isBold) { var bold = new Bold( ); font.Append(bold); } var color = new DocumentFormat.OpenXml.Spreadsheet.Color { Rgb = new HexBinaryValue { Value = ColorTranslator.ToHtml( Color.FromArgb( foreColor.A, foreColor.R, foreColor.G, foreColor.B)).Replace("#", "") } }; font.Append(color); styleSheet.Fonts.Append(font); UInt32Value result = styleSheet.Fonts.Count; styleSheet.Fonts.Count++; return(result); }