예제 #1
0
        internal static WorksheetRangeStyle GetRangeStyleObject(object p)
        {
            if (p is WorksheetRangeStyle)
            {
                return((WorksheetRangeStyle)p);
            }
            else if (p is ObjectValue)
            {
                var obj = (ObjectValue)p;

                WorksheetRangeStyle style = new WorksheetRangeStyle();

                SolidColor color;

                object backColor = obj["backgroundColor"];
                if (TextFormatHelper.DecodeColor(ScriptRunningMachine.ConvertToString(backColor), out color))
                {
                    style.Flag     |= PlainStyleFlag.BackColor;
                    style.BackColor = color;
                }

                return(style);
            }
            else
            {
                return(null);
            }
        }
예제 #2
0
        public RSCellStyleObject(Worksheet sheet, Cell cell)
        {
            this.sheet = sheet;
            this.Cell  = cell;

            this["backgroundColor"] = new ExternalProperty(
                () => TextFormatHelper.EncodeColor(cell.InnerStyle.BackColor),
                (v) =>
            {
                SolidColor color;

                if (TextFormatHelper.DecodeColor(ScriptRunningMachine.ConvertToString(v), out color))
                {
                    this.sheet.SetCellStyleOwn(cell.InternalPos, new WorksheetRangeStyle
                    {
                        Flag      = PlainStyleFlag.BackColor,
                        BackColor = color,
                    });

                    this.sheet.RequestInvalidate();
                }
            });

            this["color"] = new ExternalProperty(
                () => TextFormatHelper.EncodeColor(cell.InnerStyle.TextColor),
                (v) =>
            {
                SolidColor color;

                if (TextFormatHelper.DecodeColor(ScriptRunningMachine.ConvertToString(v), out color))
                {
                    this.sheet.SetCellStyleOwn(cell.InternalPos, new WorksheetRangeStyle
                    {
                        Flag      = PlainStyleFlag.TextColor,
                        TextColor = color,
                    });

                    this.sheet.RequestInvalidate();
                }
            });

            this["fontName"] = new ExternalProperty(() => cell.Style.FontName,
                                                    (v) => cell.Style.FontName = ScriptRunningMachine.ConvertToString(v));

            this["fontSize"] = new ExternalProperty(
                () => cell.Style.FontSize,
                (v) => cell.Style.FontSize = TextFormatHelper.GetFloatPixelValue(ScriptRunningMachine.ConvertToString(v),
                                                                                 System.Drawing.SystemFonts.DefaultFont.Size));

            this["align"] = new ExternalProperty(
                () => cell.Style.HAlign,
                (v) =>
            {
                this.sheet.SetCellStyleOwn(cell.InternalPos, new WorksheetRangeStyle
                {
                    Flag   = PlainStyleFlag.HorizontalAlign,
                    HAlign = XmlFileFormatHelper.DecodeHorizontalAlign(ScriptRunningMachine.ConvertToString(v)),
                });

                this.sheet.RequestInvalidate();
            });

            this["valign"] = new ExternalProperty(
                () => cell.Style.VAlign,
                (v) =>
            {
                this.sheet.SetCellStyleOwn(cell.InternalPos, new WorksheetRangeStyle
                {
                    Flag   = PlainStyleFlag.VerticalAlign,
                    VAlign = XmlFileFormatHelper.DecodeVerticalAlign(ScriptRunningMachine.ConvertToString(v)),
                });

                this.sheet.RequestInvalidate();
            });
        }
예제 #3
0
        internal static WorksheetRangeStyle ConvertFromXmlStyle(Worksheet grid, RGXmlCellStyle xmlStyle,
                                                                CultureInfo culture)
        {
            WorksheetRangeStyle style = new WorksheetRangeStyle();

            if (xmlStyle == null)
            {
                return(style);
            }

            // back color
            if (!string.IsNullOrEmpty(xmlStyle.backColor))
            {
                SolidColor color;

                if (TextFormatHelper.DecodeColor(xmlStyle.backColor, out color))
                {
                    style.Flag     |= PlainStyleFlag.BackColor;
                    style.BackColor = color;
                }
            }

            // fill pattern
            if (xmlStyle.fillPattern != null)
            {
                SolidColor color;
                if (TextFormatHelper.DecodeColor(xmlStyle.fillPattern.color, out color))
                {
                    style.Flag            |= PlainStyleFlag.FillPattern;
                    style.FillPatternColor = color;
                    style.FillPatternStyle = (HatchStyles)xmlStyle.fillPattern.patternStyleId;
                }
            }

            // text color
            if (!string.IsNullOrEmpty(xmlStyle.textColor))
            {
                SolidColor color;
                if (TextFormatHelper.DecodeColor(xmlStyle.textColor, out color))
                {
                    style.Flag     |= PlainStyleFlag.TextColor;
                    style.TextColor = color;
                }
            }

            // horizontal align
            if (!string.IsNullOrEmpty(xmlStyle.hAlign))
            {
                style.Flag  |= PlainStyleFlag.HorizontalAlign;
                style.HAlign = XmlFileFormatHelper.DecodeHorizontalAlign(xmlStyle.hAlign);
            }
            // vertical align
            if (!string.IsNullOrEmpty(xmlStyle.vAlign))
            {
                style.Flag  |= PlainStyleFlag.VerticalAlign;
                style.VAlign = XmlFileFormatHelper.DecodeVerticalAlign(xmlStyle.vAlign);
            }

            // font name
            if (!string.IsNullOrEmpty(xmlStyle.font))
            {
                style.Flag    |= PlainStyleFlag.FontName;
                style.FontName = xmlStyle.font;
            }
            // font size
            if (xmlStyle.fontSize != null)
            {
                style.Flag    |= PlainStyleFlag.FontSize;
                style.FontSize = TextFormatHelper.GetFloatValue(xmlStyle.fontSize, grid.RootStyle.FontSize, culture);
            }

            // bold
            if (xmlStyle.bold != null)
            {
                style.Flag |= PlainStyleFlag.FontStyleBold;
                style.Bold  = xmlStyle.bold == "true";
            }
            // italic
            if (xmlStyle.italic != null)
            {
                style.Flag  |= PlainStyleFlag.FontStyleItalic;
                style.Italic = xmlStyle.italic == "true";
            }
            // strikethrough
            if (xmlStyle.strikethrough != null)
            {
                style.Flag         |= PlainStyleFlag.FontStyleStrikethrough;
                style.Strikethrough = xmlStyle.strikethrough == "true";
            }
            // underline
            if (xmlStyle.underline != null)
            {
                style.Flag     |= PlainStyleFlag.FontStyleUnderline;
                style.Underline = xmlStyle.underline == "true";
            }

            // text-wrap
            if (!string.IsNullOrEmpty(xmlStyle.textWrap))
            {
                style.Flag        |= PlainStyleFlag.TextWrap;
                style.TextWrapMode = XmlFileFormatHelper.DecodeTextWrapMode(xmlStyle.textWrap);
            }

            // padding
            if (!string.IsNullOrEmpty(xmlStyle.indent))
            {
                style.Flag |= PlainStyleFlag.Indent;

                int indent = TextFormatHelper.GetPixelValue(xmlStyle.indent, 0);
                if (indent > 0 && indent < 65535)
                {
                    style.Indent = (ushort)indent;
                }
            }

            // padding
            if (!string.IsNullOrEmpty(xmlStyle.padding))
            {
                style.Flag   |= PlainStyleFlag.Padding;
                style.Padding = TextFormatHelper.DecodePadding(xmlStyle.padding);
            }

            // rotate angle
            int angle;

            if (!string.IsNullOrEmpty(xmlStyle.rotateAngle) &&
                int.TryParse(xmlStyle.rotateAngle, out angle))
            {
                style.Flag         |= PlainStyleFlag.RotationAngle;
                style.RotationAngle = angle;
            }

            return(style);
        }