internal ExcelColor(ExcelStyles styles, OfficeOpenXml.XmlHelper.ChangedEventHandler ChangedEvent, int worksheetID, string address, eStyleClass cls, StyleBase parent) : 
     base(styles, ChangedEvent, worksheetID, address)
     
 {
     _parent = parent;
     _cls = cls;
 }
Exemple #2
0
        private int GetIdBorder(eStyleClass styleClass, eStyleProperty styleProperty, object value)
        {
            ExcelBorderXml border = Border.Copy();

            switch (styleClass)
            {
            case eStyleClass.BorderBottom:
                SetBorderItem(border.Bottom, styleProperty, value);
                break;

            case eStyleClass.BorderDiagonal:
                SetBorderItem(border.Diagonal, styleProperty, value);
                break;

            case eStyleClass.BorderLeft:
                SetBorderItem(border.Left, styleProperty, value);
                break;

            case eStyleClass.BorderRight:
                SetBorderItem(border.Right, styleProperty, value);
                break;

            case eStyleClass.BorderTop:
                SetBorderItem(border.Top, styleProperty, value);
                break;

            case eStyleClass.Border:
                if (styleProperty == eStyleProperty.BorderDiagonalUp)
                {
                    border.DiagonalUp = (bool)value;
                }
                else if (styleProperty == eStyleProperty.BorderDiagonalDown)
                {
                    border.DiagonalDown = (bool)value;
                }
                else
                {
                    throw (new Exception("Invalid property for class Border."));
                }
                break;

            default:
                throw (new Exception("Invalid class/property for class Border."));
            }
            int    subId;
            string id = border.Id;

            subId = _styles.Borders.FindIndexByID(id);
            if (subId == int.MinValue)
            {
                return(_styles.Borders.Add(id, border));
            }
            return(subId);
        }
        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;
        }
        private int GetIdBorder(eStyleClass styleClass, eStyleProperty styleProperty, object value)
        {
            ExcelBorderXml border = Border.Copy();

            switch (styleClass)
            {
                case eStyleClass.BorderBottom:
                    SetBorderItem(border.Bottom, styleProperty, value);
                    break;
                case eStyleClass.BorderDiagonal:
                    SetBorderItem(border.Diagonal, styleProperty, value);
                    break;
                case eStyleClass.BorderLeft:
                    SetBorderItem(border.Left, styleProperty, value);
                    break;
                case eStyleClass.BorderRight:
                    SetBorderItem(border.Right, styleProperty, value);
                    break;
                case eStyleClass.BorderTop:
                    SetBorderItem(border.Top, styleProperty, value);
                    break;
                case eStyleClass.Border:
                    if (styleProperty == eStyleProperty.BorderDiagonalUp)
                    {
                        border.DiagonalUp = (bool)value;
                    }
                    else if (styleProperty == eStyleProperty.BorderDiagonalDown)
                    {
                        border.DiagonalDown = (bool)value;
                    }
                    else
                    {
                        throw (new Exception("Invalid property for class Border."));
                    }
                    break;
                default:
                    throw (new Exception("Invalid class/property for class Border."));
            }
            int subId;
            string id = border.Id;
            subId = _styles.Borders.FindIndexByID(id);
            if (subId == int.MinValue)
            {
                return _styles.Borders.Add(id, border);
            }
            return subId;
        }
        internal int GetNewID(ExcelStyleCollection<ExcelXfs> xfsCol, StyleBase styleObject, eStyleClass styleClass, eStyleProperty styleProperty, object value)
        {
            ExcelXfs newXfs = this.Copy();
            switch(styleClass)
            {
                case eStyleClass.Numberformat:
                    newXfs.NumberFormatId = GetIdNumberFormat(styleProperty, value);
                    styleObject.SetIndex(newXfs.NumberFormatId);
                    break;
                case eStyleClass.Font:
                {
                    newXfs.FontId = GetIdFont(styleProperty, value);
                    styleObject.SetIndex(newXfs.FontId);
                    break;
                }
                case eStyleClass.Fill:
                case eStyleClass.FillBackgroundColor:
                case eStyleClass.FillPatternColor:
                    newXfs.FillId = GetIdFill(styleClass, styleProperty, value);
                    styleObject.SetIndex(newXfs.FillId);
                    break;
                case eStyleClass.GradientFill:
                case eStyleClass.FillGradientColor1:
                case eStyleClass.FillGradientColor2:
                    newXfs.FillId = GetIdGradientFill(styleClass, styleProperty, value);
                    styleObject.SetIndex(newXfs.FillId);
                    break;
                case eStyleClass.Border:
                case eStyleClass.BorderBottom:
                case eStyleClass.BorderDiagonal:
                case eStyleClass.BorderLeft:
                case eStyleClass.BorderRight:
                case eStyleClass.BorderTop:
                    newXfs.BorderId = GetIdBorder(styleClass, styleProperty, value);
                    styleObject.SetIndex(newXfs.BorderId);
                    break;
                case eStyleClass.Style:
                    switch(styleProperty)
                    {
                        case eStyleProperty.XfId:
                            newXfs.XfId = (int)value;
                            break;
                        case eStyleProperty.HorizontalAlign:
                            newXfs.HorizontalAlignment=(ExcelHorizontalAlignment)value;
                            break;
                        case eStyleProperty.VerticalAlign:
                            newXfs.VerticalAlignment = (ExcelVerticalAlignment)value;
                            break;
                        case eStyleProperty.WrapText:
                            newXfs.WrapText = (bool)value;
                            break;
                        case eStyleProperty.ReadingOrder:
                            newXfs.ReadingOrder = (ExcelReadingOrder)value;
                            break;
                        case eStyleProperty.ShrinkToFit:
                            newXfs.ShrinkToFit=(bool)value;
                            break;
                        case eStyleProperty.Indent:
                            newXfs.Indent = (int)value;
                            break;
                        case eStyleProperty.TextRotation:
                            newXfs.TextRotation = (int)value;
                            break;
                        case eStyleProperty.Locked:
                            newXfs.Locked = (bool)value;
                            break;
                        case eStyleProperty.Hidden:
                            newXfs.Hidden = (bool)value;
                            break;
                        default:
                            throw (new Exception("Invalid property for class style."));

                    }
                    break;
                default:
                    break;
            }
            int id = xfsCol.FindIndexByID(newXfs.Id);
            if (id < 0)
            {
                return xfsCol.Add(newXfs.Id, newXfs);
            }
            return id;
        }
Exemple #7
0
        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);
        }
Exemple #8
0
        internal int GetNewID(ExcelStyleCollection <ExcelXfs> xfsCol, StyleBase styleObject, eStyleClass styleClass, eStyleProperty styleProperty, object value)
        {
            ExcelXfs newXfs = this.Copy();

            switch (styleClass)
            {
            case eStyleClass.Numberformat:
                newXfs.NumberFormatId = GetIdNumberFormat(styleProperty, value);
                styleObject.SetIndex(newXfs.NumberFormatId);
                break;

            case eStyleClass.Font:
            {
                newXfs.FontId = GetIdFont(styleProperty, value);
                styleObject.SetIndex(newXfs.FontId);
                break;
            }

            case eStyleClass.Fill:
            case eStyleClass.FillBackgroundColor:
            case eStyleClass.FillPatternColor:
                newXfs.FillId = GetIdFill(styleClass, styleProperty, value);
                styleObject.SetIndex(newXfs.FillId);
                break;

            case eStyleClass.GradientFill:
            case eStyleClass.FillGradientColor1:
            case eStyleClass.FillGradientColor2:
                newXfs.FillId = GetIdGradientFill(styleClass, styleProperty, value);
                styleObject.SetIndex(newXfs.FillId);
                break;

            case eStyleClass.Border:
            case eStyleClass.BorderBottom:
            case eStyleClass.BorderDiagonal:
            case eStyleClass.BorderLeft:
            case eStyleClass.BorderRight:
            case eStyleClass.BorderTop:
                newXfs.BorderId = GetIdBorder(styleClass, styleProperty, value);
                styleObject.SetIndex(newXfs.BorderId);
                break;

            case eStyleClass.Style:
                switch (styleProperty)
                {
                case eStyleProperty.XfId:
                    newXfs.XfId = (int)value;
                    break;

                case eStyleProperty.HorizontalAlign:
                    newXfs.HorizontalAlignment = (ExcelHorizontalAlignment)value;
                    break;

                case eStyleProperty.VerticalAlign:
                    newXfs.VerticalAlignment = (ExcelVerticalAlignment)value;
                    break;

                case eStyleProperty.WrapText:
                    newXfs.WrapText = (bool)value;
                    break;

                case eStyleProperty.ReadingOrder:
                    newXfs.ReadingOrder = (ExcelReadingOrder)value;
                    break;

                case eStyleProperty.ShrinkToFit:
                    newXfs.ShrinkToFit = (bool)value;
                    break;

                case eStyleProperty.Indent:
                    newXfs.Indent = (int)value;
                    break;

                case eStyleProperty.TextRotation:
                    newXfs.TextRotation = (int)value;
                    break;

                case eStyleProperty.Locked:
                    newXfs.Locked = (bool)value;
                    break;

                case eStyleProperty.Hidden:
                    newXfs.Hidden = (bool)value;
                    break;

                default:
                    throw (new Exception("Invalid property for class style."));
                }
                break;

            default:
                break;
            }
            int id = xfsCol.FindIndexByID(newXfs.Id);

            if (id < 0)
            {
                return(xfsCol.Add(newXfs.Id, newXfs));
            }
            return(id);
        }
 internal StyleChangeEventArgs(eStyleClass styleclass, eStyleProperty styleProperty, object value, int positionID, string address)
 {
     StyleClass = styleclass;
     StyleProperty=styleProperty;
     Value = value;
     Address = address;
     PositionID = positionID;
 }
        internal ExcelBorderItem (ExcelStyles styles, Zephyr.Utils.EPPlus.XmlHelper.ChangedEventHandler ChangedEvent, int worksheetID, string address, eStyleClass cls, StyleBase parent) : 
            base(styles, ChangedEvent, worksheetID, address)
	    {
            _cls=cls;
            _parent = parent;
	    }
Exemple #11
0
        private int GetIdFill(eStyleClass styleClass, eStyleProperty styleProperty, object value)
        {
            ExcelFillXml fill = Fill.Copy();

            switch (styleProperty)
            {
                case eStyleProperty.PatternType:
                    fill.PatternType = (ExcelFillStyle)value;
                    break;
                case eStyleProperty.Color:
                    if (fill.PatternType == ExcelFillStyle.None)
                    {
                        throw (new Exception("Can't set color when patterntype is not set."));
                    }
                    if (styleClass==eStyleClass.FillPatternColor)
                    {
                        fill.PatternColor.Rgb = value.ToString();
                    }
                    else
                    {
                        fill.BackgroundColor.Rgb = value.ToString();
                    }
                    break;
                default:
                    throw (new Exception("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;
        }