private static void StyleCells(ExcelStyle style) { style.Border.Top.Style = ExcelBorderStyle.Thin; style.Border.Bottom.Style = ExcelBorderStyle.Thin; style.Border.Left.Style = ExcelBorderStyle.Thin; style.Border.Right.Style = ExcelBorderStyle.Thin; style.Border.Top.Color.SetColor(Color.FromArgb(85, 85, 85)); style.Border.Bottom.Color.SetColor(Color.FromArgb(85, 85, 85)); style.Border.Left.Color.SetColor(Color.FromArgb(85, 85, 85)); style.Border.Right.Color.SetColor(Color.FromArgb(85, 85, 85)); }
private static void StyleHeader(ExcelStyle style) { style.Font.Bold = true; style.Fill.PatternType = ExcelFillStyle.Solid; style.Fill.BackgroundColor.SetColor(Color.FromArgb(50, 118, 177)); style.Font.Color.SetColor(Color.FromArgb(255, 255, 255)); }
/// <summary> /// Fills a <see cref="OfficeOpenXml.Style.ExcelStyle" /> object with model data. /// </summary> /// <param name="style"><see cref="OfficeOpenXml.Style.ExcelStyle" /> object.</param> /// <param name="model">Style model definition.</param> /// <param name="useAlternate"><b>true</b> for use alternate color; Otherwise <b></b>.</param> /// <exception cref="System.ArgumentNullException">If <paramref name="style" /> is <c>null</c>.</exception> /// <exception cref="System.ArgumentNullException">If <paramref name="model" /> is <c>null</c>.</exception> public static void FormatFromModel(this ExcelStyle style, StyleModel model, bool useAlternate = false) { SentinelHelper.ArgumentNull(style); SentinelHelper.ArgumentNull(model); var hasInheritStyle = !string.IsNullOrEmpty(model.Inherits); if (hasInheritStyle) { var inheritStyle = model.TryGetInheritStyle(); model.Combine(inheritStyle); } style.Font.SetFromFont(model.Font.ToFont()); style.Font.Color.SetColor(model.Font.GetColor()); var content = model.Content; style.VerticalAlignment = content.Alignment.Vertical.ToEppVerticalAlignment(); style.HorizontalAlignment = content.Alignment.Horizontal.ToEppHorizontalAlignment(); style.Fill.PatternType = content.Pattern.PatternType.ToEppPatternFillStyle(); if (style.Fill.PatternType != ExcelFillStyle.None) { style.Fill.BackgroundColor.SetColor(useAlternate ? content.GetAlternateColor() : content.GetColor()); style.Fill.PatternColor.SetColor(content.Pattern.GetColor()); } style.Numberformat.Format = content.DataType.GetDataFormat().ToEppDataFormat(content.DataType); foreach (var border in model.Borders) { style.Border.CreateFromModel(border); } }
public ExcelNamedStyle CreateNamedStyle(string name, ExcelStyle template) { if (_wb.Styles.NamedStyles.ExistsKey(name)) { throw new Exception(string.Format("Key {0} already exists in collection", name)); } var style = new ExcelNamedStyleXml(NameSpaceManager, this); int xfIdCopy, positionID; ExcelStyles styles; if (template == null) { // style.Style = new ExcelStyle(this, NamedStylePropertyChange, -1, name, 0); xfIdCopy = 0; positionID = -1; styles = this; } else { xfIdCopy = template.PositionID < 0 ? template.Index : template.XfId; positionID = -1; styles = template.Styles; } //Clone named style var styleXfId = CloneStyle(styles, xfIdCopy, true); //Clone cells style CellStyleXfs[styleXfId].XfId = CellStyleXfs.Count - 1; var xfId = CloneStyle(styles, xfIdCopy, true, true); //Always add a new style (We create a new named style here) CellXfs[xfId].XfId = styleXfId; style.Style = new ExcelStyle(this, NamedStylePropertyChange, positionID, name, styleXfId); style.StyleXfId = styleXfId; style.Name = name; var ix = _wb.Styles.NamedStyles.Add(style.Name, style); style.Style.Index = ix; return(new ExcelNamedStyle(style)); }
public ExcelNamedStyleXml CreateNamedStyle(string name, ExcelStyle Template) { if (_wb.Styles.NamedStyles.ExistsKey(name)) { throw new Exception(string.Format("Key {0} already exists in collection", name)); } ExcelNamedStyleXml style; style = new ExcelNamedStyleXml(NameSpaceManager, this); int xfIdCopy, positionID; ExcelStyles styles; if (Template == null) { // style.Style = new ExcelStyle(this, NamedStylePropertyChange, -1, name, 0); xfIdCopy = 0; positionID = -1; styles = this; } else { if (Template.PositionID < 0 && Template.Styles==this) { xfIdCopy = Template.Index; positionID=Template.PositionID; styles = this; //style.Style = new ExcelStyle(this, NamedStylePropertyChange, Template.PositionID, name, Template.Index); //style.StyleXfId = Template.Index; } else { xfIdCopy = Template.XfId; positionID = -1; styles = Template.Styles; } } //Clone namedstyle int styleXfId = CloneStyle(styles, xfIdCopy, true); //Close cells style CellStyleXfs[styleXfId].XfId = CellStyleXfs.Count-1; int xfid = CloneStyle(styles, xfIdCopy, false, true); //Always add a new style (We create a new named style here) CellXfs[xfid].XfId = styleXfId; style.Style = new ExcelStyle(this, NamedStylePropertyChange, positionID, name, styleXfId); style.StyleXfId = styleXfId; style.Name = name; int ix =_wb.Styles.NamedStyles.Add(style.Name, style); style.Style.SetIndex(ix); //style.Style.XfId = ix; return style; }
/// <summary> /// Fills a <see cref="ExcelStyle"/> object with model data. /// </summary> /// <param name="style">A <see cref="ExcelStyle"/> reference.</param> /// <param name="model">Style model definition.</param> /// <param name="useAlternate"><b>true</b> for use alternate color; Otherwise <b>false</b>.</param> /// <exception cref="System.ArgumentNullException">If <paramref name="style"/> is <b>null</b>.</exception> /// <exception cref="System.ArgumentNullException">If <paramref name="model"/> is <b>null</b>.</exception> public static void FormatFromModel(this ExcelStyle style, XlsxCellStyle model, bool useAlternate = false) { SentinelHelper.ArgumentNull(style, nameof(style)); SentinelHelper.ArgumentNull(model, nameof(model)); string concreteStyle = model.GetType().Name; switch (concreteStyle) { case "XlsxCellStyle": { var cellStyle = (XlsxCellStyle)model; var hasInheritStyle = !string.IsNullOrEmpty(cellStyle.Inherits); if (hasInheritStyle) { var inheritStyle = cellStyle.TryGetInheritStyle(); cellStyle.Combine((XlsxCellStyle)inheritStyle); } style.Font.SetFromFont(cellStyle.Font.ToFont()); style.Font.Color.SetColor(cellStyle.Font.GetColor()); XlsxCellContent cellContent = cellStyle.Content; style.VerticalAlignment = cellContent.Alignment.Vertical.ToEppVerticalAlignment(); style.HorizontalAlignment = cellContent.Alignment.Horizontal.ToEppHorizontalAlignment(); style.Numberformat.Format = cellContent.DataType.GetDataFormat().ToEppDataFormat(cellContent.DataType); if (cellContent.Color.Equals(BaseContent.DefaultColor, StringComparison.OrdinalIgnoreCase)) { style.Fill.PatternType = ExcelFillStyle.None; } else { style.Fill.PatternType = cellContent.Pattern.PatternType.ToEppPatternFillStyle(); if (style.Fill.PatternType != ExcelFillStyle.None) { style.Fill.BackgroundColor.SetColor(useAlternate ? cellContent.GetAlternateColor() : cellContent.GetColor()); style.Fill.PatternColor.SetColor(cellContent.Pattern.GetColor()); } } foreach (var border in cellStyle.Borders) { style.Border.CreateFromModel(border); } } break; default: { var hasInheritStyle = !string.IsNullOrEmpty(model.Inherits); if (hasInheritStyle) { var inheritStyle = model.TryGetInheritStyle(); model.Combine((XlsxCellStyle)inheritStyle); } style.Font.SetFromFont(model.Font.ToFont()); style.Font.Color.SetColor(model.Font.GetColor()); style.HorizontalAlignment = model.Content.Alignment.Horizontal.ToEppHorizontalAlignment(); if (model.Content.Color.Equals(BaseContent.DefaultColor, StringComparison.OrdinalIgnoreCase)) { style.Fill.PatternType = ExcelFillStyle.None; } else { style.Fill.BackgroundColor.SetColor(model.Content.GetColor()); } foreach (var border in model.Borders) { style.Border.CreateFromModel(border); } } break; } }
public static void TitleCell(ExcelStyle style) { style.Fill.PatternType = ExcelFillStyle.Solid; style.Fill.BackgroundColor.SetColor(TitleColor); style.Font.Bold = true; }
public static void HighlightedCell(ExcelStyle style) { style.Fill.PatternType = ExcelFillStyle.Solid; style.Fill.BackgroundColor.SetColor(RowColor); }
public ExcelNamedStyleXml CreateNamedStyle(string name, ExcelStyle Template) { if (_wb.Styles.NamedStyles.ExistsKey(name)) { throw new Exception(string.Format("Key {0} already exist in collection", name)); } ExcelNamedStyleXml style; style = new ExcelNamedStyleXml(NameSpaceManager, this); if (Template == null) { style.Style = new ExcelStyle(this, NamedStylePropertyChange, -1, name, 0); } else { style.Style = new ExcelStyle(this, NamedStylePropertyChange, -1, name, Template.Index); style.StyleXfId = Template.Index; } style.Name = name; int ix =_wb.Styles.NamedStyles.Add(style.Name, style); style.Style.SetIndex(ix); //style.Style.XfId = ix; return style; }
public ExcelNamedStyle Create(string name, ExcelStyle template) { return(_styles.CreateNamedStyle(name, template)); }
static void fmtHeader(ExcelStyle st) { st.Font.Bold = true; st.Fill.PatternType = ExcelFillStyle.Solid; st.Fill.BackgroundColor.SetColor(Color.LightGray); st.Font.Color.SetColor(Color.Black); st.ShrinkToFit = false; }
static void fmtTitle(ExcelStyle st) { st.Font.Bold = true; st.Fill.PatternType = ExcelFillStyle.Solid; st.Fill.BackgroundColor.SetColor(lib.formHtmlColor("337ab7")); st.Font.Color.SetColor(Color.White); st.Font.Size = 16; st.ShrinkToFit = false; }