Esempio n. 1
0
        /// <summary>
        /// Fills a <see cref="OfficeOpenXml.Drawing.ExcelDrawingBorder"/> object with model data.
        /// </summary>
        /// <param name="border"><see cref="OfficeOpenXml.Drawing.ExcelDrawingBorder"/> object.</param>
        /// <param name="element">Chart element.</param>
        /// <param name="model">Chart border model definition.</param>
        /// <exception cref="T:System.ArgumentNullException">If <paramref name="border" /> is <c>null</c>.</exception>
        /// <exception cref="T:System.ArgumentNullException">If <paramref name="model" /> is <c>null</c>.</exception>
        /// <exception cref="T:System.ComponentModel.InvalidEnumArgumentException">The value specified is outside the range of valid values.</exception>
        public static void FormatFromModel(this ExcelDrawingBorder border, KnownChartElement element, ChartBorderModel model)
        {
            SentinelHelper.IsEnumValid(element);
            SentinelHelper.ArgumentNull(model);
            SentinelHelper.ArgumentNull(border);

            if (model.Show == YesNo.Yes)
            {
                border.Fill.Color = model.GetColor();
                border.Width      = model.Width.ToEppBorderWidth();
                border.LineStyle  = model.Style.ToEppLineStyle();
            }

            if (model.Shadow.Show == YesNo.No)
            {
                return;
            }

            var root  = ChartXmlHelper.FromKnownChartElement(element);
            var exist = ChartXmlHelper.TryGetElementFrom(root, "c:spPr", out var shapePropertiesNode);

            shapePropertiesNode.AddEffectContainerNode(model.Shadow);

            if (!exist)
            {
                root.AppendChild(shapePropertiesNode);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Fills a <see cref="OfficeOpenXml.Drawing.Chart.ExcelChartTitle"/> object with model data.
        /// </summary>
        /// <param name="title"><see cref="OfficeOpenXml.Drawing.Chart.ExcelChartTitle"/> object.</param>
        /// <param name="element">A <see cref="KnownChartElement" /> value.</param>
        /// <param name="model">Chart title model definition.</param>
        private static void FormatFromModel(this ExcelChartTitle title, KnownChartElement element, ChartTitleModel model)
        {
            if (model.Show == YesNo.No)
            {
                return;
            }

            if (!string.IsNullOrEmpty(model.Text))
            {
                title.Text = model.Text;
                title.Font.SetFromFont(model.Font.ToFont());
                title.Font.Color = model.Font.GetColor();

                title.Rotation     = model.Orientation.ToAngle();
                title.TextVertical = model.Orientation == KnownAxisOrientation.Vertical ? eTextVerticalType.WordArtVertical : eTextVerticalType.Horizontal;
            }

            title.Border.FormatFromModel(element, model.Border);
        }
Esempio n. 3
0
        /// <summary>
        /// Returns a value than represents a known node.
        /// </summary>
        /// <param name="element">A <see cref="KnownChartElement"/> value.</param>
        /// <returns>
        /// <see cref="XmlNode"/> reference that contains <c>Xml</c> node.
        /// </returns>
        /// <exception cref="InvalidEnumArgumentException">The value specified is outside the range of valid values.</exception>
        public XmlNode FromKnownChartElement(KnownChartElement element)
        {
            SentinelHelper.IsEnumValid(element);

            XmlNode knownRootNode = null;

            switch (element)
            {
            case KnownChartElement.Self:
                knownRootNode = GetXmlNode(ChartSpaceRootNode);
                break;

            case KnownChartElement.Legend:
                knownRootNode = GetXmlNode(ChartLegendRootNode);
                break;

            case KnownChartElement.PlotArea:
                knownRootNode = GetXmlNode(ChartPlotAreaRootNode);
                break;

            case KnownChartElement.ChartTitle:
                knownRootNode = GetXmlNode(ChartTitleRootNode);
                break;

            case KnownChartElement.PrimaryCategoryAxis:
                knownRootNode = GetElementsByTagName("c:catAx").ToList()[0];
                break;

            case KnownChartElement.PrimaryValueAxis:
                knownRootNode = GetElementsByTagName("c:valAx").ToList()[0];
                break;

            case KnownChartElement.SecondaryCategoryAxis:
                var catAxisXmlList = GetElementsByTagName("c:catAx").ToList();

                SentinelHelper.IsTrue(catAxisXmlList.Count <= 1, "Error the secondary axis does not exist");
                knownRootNode = catAxisXmlList[1];
                break;

            case KnownChartElement.SecondaryValueAxis:
                var valAxisXmlList = GetElementsByTagName("c:valAx").ToList();

                SentinelHelper.IsTrue(valAxisXmlList.Count <= 1, "Error the secondary axis does not exist");
                knownRootNode = valAxisXmlList[1];
                break;

            case KnownChartElement.PrimaryCategoryAxisTitle:
                knownRootNode = GetXmlNode(GetElementsByTagName("c:catAx").ToList()[0], "c:title");
                break;

            case KnownChartElement.PrimaryValueAxisTitle:
                knownRootNode = GetXmlNode(GetElementsByTagName("c:valAx").ToList()[0], "c:title");
                break;

            case KnownChartElement.SecondaryCategoryAxisTitle:
                var catAxisXmlList1 = GetElementsByTagName("c:catAx").ToList();

                SentinelHelper.IsTrue(catAxisXmlList1.Count <= 1, "Error the secondary axis does not exist");
                knownRootNode = GetXmlNode(catAxisXmlList1[1], "c:title");
                break;

            case KnownChartElement.SecondaryValueAxisTitle:
                var valAxisXmlList2 = GetElementsByTagName("c:valAx").ToList();

                SentinelHelper.IsTrue(valAxisXmlList2.Count <= 1, "Error the secondary axis does not exist");
                knownRootNode = GetXmlNode(valAxisXmlList2[1], "c:title");
                break;
            }

            return(knownRootNode);
        }