Пример #1
0
        private int GetIdFont(eStyleProperty styleProperty, object value)
        {
            ExcelFontXml fnt = Font.Copy();

            switch (styleProperty)
            {
            case eStyleProperty.Name:
                fnt.Name = value.ToString();
                break;

            case eStyleProperty.Size:
                fnt.Size = (float)value;
                break;

            case eStyleProperty.Family:
                fnt.Family = (int)value;
                break;

            case eStyleProperty.Bold:
                fnt.Bold = (bool)value;
                break;

            case eStyleProperty.Italic:
                fnt.Italic = (bool)value;
                break;

            case eStyleProperty.Color:
                fnt.Color.Rgb = value.ToString();
                break;

            case eStyleProperty.Tint:
                fnt.Color.Tint = (decimal)value;
                break;

            case eStyleProperty.IndexedColor:
                fnt.Color.Indexed = (int)value;
                break;

            case eStyleProperty.AutoColor:
                fnt.Color.Auto = (bool)value;
                break;

            case eStyleProperty.VerticalAlign:
                fnt.VerticalAlign = ((ExcelVerticalAlignmentFont)value) == ExcelVerticalAlignmentFont.None ? "" : value.ToString().ToLower(CultureInfo.InvariantCulture);
                break;

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

            subId = _styles.Fonts.FindIndexByID(id);
            if (subId == int.MinValue)
            {
                return(_styles.Fonts.Add(id, fnt));
            }
            return(subId);
        }
Пример #2
0
 internal StyleChangeEventArgs(eStyleClass styleclass, eStyleProperty styleProperty, object value, int positionID, string address)
 {
     StyleClass    = styleclass;
     StyleProperty = styleProperty;
     Value         = value;
     Address       = address;
     PositionID    = positionID;
 }
Пример #3
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);
        }
Пример #4
0
 private void SetBorderItem(ExcelBorderItemXml excelBorderItem, eStyleProperty styleProperty, object value)
 {
     if (styleProperty == eStyleProperty.Style)
     {
         excelBorderItem.Style = (ExcelBorderStyle)value;
     }
     else if (styleProperty == eStyleProperty.Color || styleProperty == eStyleProperty.Tint || styleProperty == eStyleProperty.IndexedColor)
     {
         if (excelBorderItem.Style == ExcelBorderStyle.None)
         {
             throw(new Exception("Can't set bordercolor when style is not set."));
         }
         excelBorderItem.Color.Rgb = value.ToString();
     }
 }
Пример #5
0
 private int GetIdNumberFormat(eStyleProperty styleProperty, object value)
 {
     if (styleProperty == eStyleProperty.Format)
     {
         ExcelNumberFormatXml item = null;
         if (!_styles.NumberFormats.FindByID(value.ToString(), ref item))
         {
             item = new ExcelNumberFormatXml(NameSpaceManager)
             {
                 Format = value.ToString(), NumFmtId = _styles.NumberFormats.NextId++
             };
             _styles.NumberFormats.Add(value.ToString(), item);
         }
         return(item.NumFmtId);
     }
     else
     {
         throw (new Exception("Invalid property for class Numberformat"));
     }
 }
Пример #6
0
        private int GetIdFont(eStyleProperty styleProperty, object value)
        {
            ExcelFontXml fnt = Font.Copy();

            switch (styleProperty)
            {
                case eStyleProperty.Name:
                    fnt.Name = value.ToString();
                    break;
                case eStyleProperty.Size:
                    fnt.Size = (float)value;
                    break;
                case eStyleProperty.Family:
                    fnt.Family = (int)value;
                    break;
                case eStyleProperty.Bold:
                    fnt.Bold = (bool)value;
                    break;
                case eStyleProperty.Italic:
                    fnt.Italic = (bool)value;
                    break;
                case eStyleProperty.Strike:
                    fnt.Strike = (bool)value;
                    break;
                case eStyleProperty.UnderlineType:
                    fnt.UnderLineType = (ExcelUnderLineType)value;
                    break;
                case eStyleProperty.Color:
                    fnt.Color.Rgb=value.ToString();
                    break;
                case eStyleProperty.VerticalAlign:
                    fnt.VerticalAlign = ((ExcelVerticalAlignmentFont)value) == ExcelVerticalAlignmentFont.None ? "" : value.ToString().ToLower();
                    break;
                default:
                    throw (new Exception("Invalid property for class Font"));
            }
            int subId;
            string id = fnt.Id;
            subId = _styles.Fonts.FindIndexByID(id);
            if (subId == int.MinValue)
            {
                return _styles.Fonts.Add(id,fnt);
            }
            return subId;
        }
Пример #7
0
        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;
        }
Пример #8
0
 private int GetIdNumberFormat(eStyleProperty styleProperty, object value)
 {
     if (styleProperty == eStyleProperty.Format)
     {
         ExcelNumberFormatXml item=null;
         if (!_styles.NumberFormats.FindByID(value.ToString(), ref item))
         {
             item = new ExcelNumberFormatXml(NameSpaceManager) { Format = value.ToString(), NumFmtId = _styles.NumberFormats.NextId++ };
             _styles.NumberFormats.Add(value.ToString(), item);
         }
         return item.NumFmtId;
     }
     else
     {
         throw (new Exception("Invalid property for class Numberformat"));
     }
 }
Пример #9
0
 private void SetBorderItem(ExcelBorderItemXml excelBorderItem, eStyleProperty styleProperty, object value)
 {
     if(styleProperty==eStyleProperty.Style)
     {
         excelBorderItem.Style = (ExcelBorderStyle)value;
     }
     else if (styleProperty == eStyleProperty.Color || styleProperty== eStyleProperty.Tint || styleProperty==eStyleProperty.IndexedColor)
     {
         if (excelBorderItem.Style == ExcelBorderStyle.None)
         {
             throw(new Exception("Can't set bordercolor when style is not set."));
         }
         excelBorderItem.Color.Rgb = value.ToString();
     }
 }
Пример #10
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;
        }
Пример #11
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;
        }
Пример #12
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;
        }
Пример #13
0
 internal StyleChangeEventArgs(eStyleClass styleclass, eStyleProperty styleProperty, object value, int positionID, string address)
 {
     StyleClass = styleclass;
     StyleProperty=styleProperty;
     Value = value;
     Address = address;
     PositionID = positionID;
 }
Пример #14
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;
        }
Пример #15
0
        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);
        }
Пример #16
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);
        }
Пример #17
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);
        }