示例#1
0
        public void WriteConditionalFormattingColorScale(ColorScale colorScale, out CT_ColorScale cfColorScale)
        {
            if (colorScale == null)
            {
                cfColorScale = null;
                return;
            }
            List <CT_Cfvo> ct_cfvo_list = new List <CT_Cfvo>();

            foreach (var ct_cfvo in colorScale.CFVOList)
            {
                ct_cfvo_list.Add(new CT_Cfvo
                {
                    val  = ct_cfvo.Value,
                    type = (ST_CfvoType)ct_cfvo.Type //1-1
                });
            }

            List <CT_Color1> ct_color1_list = new List <CT_Color1>();

            foreach (var color in colorScale.Colors)
            {
                ct_color1_list.Add(ConvertColor(color));
            }

            cfColorScale = new CT_ColorScale
            {
                cfvo  = ct_cfvo_list.ToArray(),
                color = ct_color1_list.ToArray()
            };
        }
        public XSSFColorScaleFormatting CreateColorScaleFormatting()
        {
            // Is it already there?
            if (_cfRule.IsSetColorScale() && _cfRule.type == ST_CfType.colorScale)
            {
                return(ColorScaleFormatting as XSSFColorScaleFormatting);
            }

            // Mark it as being a Color Scale
            _cfRule.type = (ST_CfType.colorScale);

            // Ensure the right element
            CT_ColorScale scale = null;

            if (_cfRule.IsSetColorScale())
            {
                scale = _cfRule.colorScale;
            }
            else
            {
                scale = _cfRule.AddNewColorScale();
            }

            // Add a default set of thresholds and colors
            if (scale.SizeOfCfvoArray() == 0)
            {
                CT_Cfvo cfvo;
                cfvo      = scale.AddNewCfvo();
                cfvo.type = (ST_CfvoType)Enum.Parse(typeof(ST_CfvoType), RangeType.MIN.name);
                cfvo      = scale.AddNewCfvo();
                cfvo.type = (ST_CfvoType)Enum.Parse(typeof(ST_CfvoType), RangeType.PERCENTILE.name);
                cfvo.val  = ("50");
                cfvo      = scale.AddNewCfvo();
                cfvo.type = (ST_CfvoType)Enum.Parse(typeof(ST_CfvoType), RangeType.MAX.name);

                for (int i = 0; i < 3; i++)
                {
                    scale.AddNewColor();
                }
            }

            // Wrap and return
            return(new XSSFColorScaleFormatting(scale));
        }
示例#3
0
        public void WriteConditionalFormattingRule(CFRule rule, string firstCell, out CT_CfRule cfRule)
        {
            ST_CfType     st_cftype     = (ST_CfType)rule.Type;
            CT_ColorScale ct_colorscale = null;
            CT_DataBar    ct_databar    = null;
            CT_IconSet    ct_iconset    = null;

            if (rule.Type == CFType.ColorScale)
            {
                WriteConditionalFormattingColorScale(rule.ColorScale, out ct_colorscale);
            }

            if (rule.Type == CFType.DataBar)
            {
                WriteConditionalFormattingDataBar(rule.DataBar, out ct_databar);
            }

            if (rule.Type == CFType.IconSet)
            {
                WriteConditionalFormattingIconSet(rule.IconSet, out ct_iconset);
            }

            if (CFRule.RequiresDxf(rule.Type))
            {
                List <string> formulas = new List <string>();

                if (!string.IsNullOrEmpty(rule.Formula1))
                {
                    formulas.Add(rule.Formula1);
                }

                if (!string.IsNullOrEmpty(rule.Formula2))
                {
                    formulas.Add(rule.Formula2);
                }

                if (!string.IsNullOrEmpty(rule.Formula3))
                {
                    formulas.Add(rule.Formula3);
                }

                cfRule = new CT_CfRule
                {
                    typeSpecified     = true,
                    type              = st_cftype,
                    priority          = rule.Priority,
                    formula           = formulas.ToArray(),
                    operatorSpecified = rule.Operator.HasValue,
                    @operator         = rule.Operator.HasValue ? (ST_ConditionalFormattingOperator)rule.Operator.Value : ST_ConditionalFormattingOperator.beginsWith,
                    text              = rule.Text,
                };
                cfRule = SetDxfStyle(cfRule, rule.Style);

                switch (rule.Type)
                {
                case CFType.Top10:
                    cfRule.percent       = rule.IsPercent;
                    cfRule.bottom        = rule.IsBottom;
                    cfRule.rankSpecified = rule.Rank.HasValue;
                    cfRule.rank          = (uint)rule.Rank.Value;
                    break;

                case CFType.AboveAverage:
                    cfRule.aboveAverage    = rule.IsAboveAverage;
                    cfRule.equalAverage    = rule.IsEqualAverage;
                    cfRule.stdDevSpecified = rule.IsStdDev;
                    cfRule.stdDev          = rule.StdDev;
                    break;

                case CFType.TimePeriod:
                    cfRule.timePeriodSpecified = true;
                    cfRule.timePeriod          = (ST_TimePeriod)rule.TimePeriod;
                    break;
                }
                return;
            }

            cfRule = new CT_CfRule
            {
                typeSpecified = true,
                type          = st_cftype,
                colorScale    = ct_colorscale,
                dataBar       = ct_databar,
                iconSet       = ct_iconset,
                priority      = rule.Priority
            };
        }
示例#4
0
 /*package*/
 public XSSFColorScaleFormatting(CT_ColorScale scale)
 {
     _scale = scale;
 }