private int GetIdGradientFill(eStyleClass styleClass, eStyleProperty styleProperty, object value) { ExcelGradientFillXml fill; if (Fill is ExcelGradientFillXml) { fill = (ExcelGradientFillXml)Fill.Copy(); } else { fill = new ExcelGradientFillXml(Fill.NameSpaceManager); fill.GradientColor1.SetColor(Color.White); fill.GradientColor2.SetColor(Color.FromArgb(79, 129, 189)); fill.Type = ExcelFillGradientType.Linear; fill.Degree = 90; fill.Top = double.NaN; fill.Bottom = double.NaN; fill.Left = double.NaN; fill.Right = double.NaN; } switch (styleProperty) { case eStyleProperty.GradientType: fill.Type = (ExcelFillGradientType)value; break; case eStyleProperty.GradientDegree: fill.Degree = (double)value; break; case eStyleProperty.GradientTop: fill.Top = (double)value; break; case eStyleProperty.GradientBottom: fill.Bottom = (double)value; break; case eStyleProperty.GradientLeft: fill.Left = (double)value; break; case eStyleProperty.GradientRight: fill.Right = (double)value; break; case eStyleProperty.Color: case eStyleProperty.Tint: case eStyleProperty.IndexedColor: case eStyleProperty.AutoColor: ExcelColorXml destColor; if (styleClass == eStyleClass.FillGradientColor1) { destColor = fill.GradientColor1; } else { destColor = fill.GradientColor2; } if (styleProperty == eStyleProperty.Color) { destColor.Rgb = value.ToString(); } else if (styleProperty == eStyleProperty.Tint) { destColor.Tint = (decimal)value; } else if (styleProperty == eStyleProperty.IndexedColor) { destColor.Indexed = (int)value; } else { destColor.Auto = (bool)value; } break; default: throw (new ArgumentException("Invalid class/property for class Fill.")); } int subId; string id = fill.Id; subId = _styles.Fills.FindIndexByID(id); if (subId == int.MinValue) { return(_styles.Fills.Add(id, fill)); } return(subId); }
private int GetIdFill(eStyleClass styleClass, eStyleProperty styleProperty, object value) { ExcelFillXml fill = Fill.Copy(); switch (styleProperty) { case eStyleProperty.PatternType: if (fill is ExcelGradientFillXml) { fill = new ExcelFillXml(NameSpaceManager); } fill.PatternType = (ExcelFillStyle)value; break; case eStyleProperty.Color: case eStyleProperty.Tint: case eStyleProperty.IndexedColor: case eStyleProperty.AutoColor: if (fill is ExcelGradientFillXml) { fill = new ExcelFillXml(NameSpaceManager); } if (fill.PatternType == ExcelFillStyle.None) { throw (new ArgumentException("Can't set color when patterntype is not set.")); } ExcelColorXml destColor; if (styleClass == eStyleClass.FillPatternColor) { destColor = fill.PatternColor; } else { destColor = fill.BackgroundColor; } if (styleProperty == eStyleProperty.Color) { destColor.Rgb = value.ToString(); } else if (styleProperty == eStyleProperty.Tint) { destColor.Tint = (decimal)value; } else if (styleProperty == eStyleProperty.IndexedColor) { destColor.Indexed = (int)value; } else { destColor.Auto = (bool)value; } break; default: throw (new ArgumentException("Invalid class/property for class Fill.")); } int subId; string id = fill.Id; subId = _styles.Fills.FindIndexByID(id); if (subId == int.MinValue) { return(_styles.Fills.Add(id, fill)); } return(subId); }