示例#1
0
        /// <summary>
        /// Updates the chart.
        /// </summary>
        /// <param name="chart">The chart.</param>
        /// <param name="sheetName">Name of the sheet.</param>
        protected override void UpdateChart(OpenXmlCompositeElement chart, string sheetName)
        {
            if (chart != null)
            {
                chart.RemoveAllChildren <LineChartSeries>();

                // Index 0 is for category axis data
                for (int index = 1; index < chartData.columnNameToSeries.Count(); index++)
                {
                    string          columnName      = GetExcelColumnName(index);
                    LineChartSeries lineChartSeries = chart.AppendChild <LineChartSeries>(new LineChartSeries());

                    UpdateSeriesText(sheetName, lineChartSeries, columnName, 1, chartData.columnNameToSeries.Skip(index).FirstOrDefault().Key);

                    // Update Category Axis data
                    CategoryAxisData catAxisData = new CategoryAxisData();
                    catAxisData.RemoveAllChildren <StringReference>();
                    catAxisData.RemoveAllChildren <NumberReference>();

                    StringReference catStringReference = GetStringReference(sheetName + "!$A$2:$A$" + (chartData.Count + 1).ToString(), chartData.Count);

                    // Series 0 is for category axis data
                    foreach (string cat in chartData.columnNameToSeries.First().Value)
                    {
                        AddStringPoint(catStringReference.StringCache, catStringReference.StringCache.Descendants <StringPoint>().Count(), cat);
                    }

                    catAxisData.Append(catStringReference);

                    // Update Values
                    NumberingCache  numberingCache;
                    PointCount      pointCount;
                    Values          values    = lineChartSeries.AppendChild <Values>(new Values());
                    NumberReference reference = CreateNumberReference(values, sheetName + "!$" + columnName + "$2:$" + columnName + "$" + (chartData.Count + 1).ToString());

                    SetNumberingCache(reference, out numberingCache, out pointCount);

                    int rowIndex = 0;

                    foreach (var point in chartData.columnNameToSeries.Skip(index).FirstOrDefault().Value)
                    {
                        AddNumericPoint(numberingCache, pointCount, rowIndex, point.ToString());
                        rowIndex += 1;
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        /// Updates the chart.
        /// </summary>
        /// <param name="chart">The chart.</param>
        /// <param name="sheetName">Name of the sheet.</param>
        protected override void UpdateChart(OpenXmlCompositeElement chart, string sheetName)
        {
            if (chart != null)
            {
                chart.RemoveAllChildren <BarChartSeries>();

                var barChartSeries = chart.InsertAt(new BarChartSeries(), 3);
                barChartSeries.Index = new Index {
                    Val = 1
                };
                barChartSeries.Order = new Order {
                    Val = 1
                };
                barChartSeries.SeriesText = new SeriesText(new NumericValue {
                    Text = chartData.xColumnName
                });

                var categoryAxisData = barChartSeries.AppendChild(new CategoryAxisData());
                var values           = barChartSeries.AppendChild(new Values());
                var stringReference  = categoryAxisData.AppendChild(new StringReference());
                var numberReference  = values.AppendChild(new NumberReference());

                var stringCache    = stringReference.AppendChild(new StringCache());
                var numberingCache = numberReference.AppendChild(new NumberingCache());

                uint rowIndex = 0;
                foreach (var xToY in chartData.xValToYValMap)
                {
                    var stringPoint = stringCache.AppendChild(new StringPoint {
                        Index = rowIndex
                    });
                    stringPoint.AppendChild(new NumericValue {
                        Text = xToY.Key
                    });

                    var numericPoint = numberingCache.AppendChild(new NumericPoint {
                        Index = rowIndex
                    });
                    numericPoint.AppendChild(new NumericValue {
                        Text = xToY.Value.ToString()
                    });
                    rowIndex++;
                }
            }
        }
示例#3
0
        /// <summary>
        /// Sets the SDT content keeping permission elements.
        /// </summary>
        /// <param name="openXmlCompositeElement">The open XML composite element.</param>
        /// <param name="newChild">The new child.</param>
        private static void SetSdtContentKeepingPermissionElements(OpenXmlCompositeElement openXmlCompositeElement, OpenXmlElement newChild)
        {
            var start = openXmlCompositeElement.Descendants <PermStart>().FirstOrDefault();
            var end   = openXmlCompositeElement.Descendants <PermEnd>().FirstOrDefault();

            openXmlCompositeElement.RemoveAllChildren();

            if (start != null)
            {
                openXmlCompositeElement.AppendChild(start);
            }

            openXmlCompositeElement.AppendChild(newChild);

            if (end != null)
            {
                openXmlCompositeElement.AppendChild(end);
            }
        }
示例#4
0
        /// <summary>
        /// Updates the chart.
        /// </summary>
        /// <param name="chart">The chart.</param>
        /// <param name="sheetName">Name of the sheet.</param>
        protected override void UpdateChart(OpenXmlCompositeElement chart, string sheetName)
        {
            if (chart != null)
            {
                chart.RemoveAllChildren <ScatterChartSeries>();
                ScatterChartSeries scatterChartSeries = chart.AppendChild <ScatterChartSeries>(new ScatterChartSeries());

                Outline outline = new Outline()
                {
                    Width = 28575
                };
                NoFill noFill = new NoFill();
                outline.Append(noFill);
                scatterChartSeries.ChartShapeProperties = new ChartShapeProperties(outline);

                UpdateSeriesText(sheetName, scatterChartSeries, "B", 1, chartData.yColumnName);

                XValues xValues = scatterChartSeries.AppendChild <XValues>(new XValues());
                YValues yValues = scatterChartSeries.AppendChild <YValues>(new YValues());

                NumberReference referenceX = CreateNumberReference(xValues, sheetName + "!$A$2:$A$" + (chartData.Count + 1).ToString());
                NumberReference referenceY = CreateNumberReference(yValues, sheetName + "!$B$2:$B$" + (chartData.Count + 1).ToString());

                NumberingCache ncX;
                PointCount     ptXCount;
                NumberingCache ncY;
                PointCount     ptYCount;

                SetNumberingCache(referenceX, out ncX, out ptXCount);
                SetNumberingCache(referenceY, out ncY, out ptYCount);

                int rowIndex = 0;

                foreach (var xToY in chartData.xValToYValMap)
                {
                    AddNumericPoint(ncX, ptXCount, rowIndex, xToY.Key.ToString());
                    AddNumericPoint(ncY, ptYCount, rowIndex, xToY.Value.ToString());
                    rowIndex += 1;
                }
            }
        }
示例#5
0
        private static void ReplaceParagraph(OpenXmlCompositeElement element, string value)
        {
            string[] vs = value?.Split('\n');
            if (vs == null)
            {
                vs = new string[1];
            }
            Paragraph sp = element.Elements <Paragraph>().Count() > 0 ? element.Elements <Paragraph>().First() : new Paragraph();

            element.RemoveAllChildren <Paragraph>();
            for (int i = 0; i < vs.Length; i++)
            {
                Paragraph p = sp.Clone() as Paragraph;
                element.AppendChild(p);
                Run r = p.Elements <Run>().Count() > 0 ? p.Elements <Run>().First() : new Run();
                p.RemoveAllChildren <Run>();
                p.AppendChild(r);
                r.RemoveAllChildren <Text>();
                r.AppendChild(new Text(vs[i]));
            }
        }
示例#6
0
        /// <summary>
        /// Sets the SDT content keeping permission elements.
        /// </summary>
        /// <param name="openXmlCompositeElement">The open XML composite element.</param>
        /// <param name="newChildren">The new children.</param>
        private void SetSdtContentKeepingPermissionElements(OpenXmlCompositeElement openXmlCompositeElement, List <OpenXmlElement> newChildren)
        {
            PermStart start = openXmlCompositeElement.Descendants <PermStart>().FirstOrDefault();
            PermEnd   end   = openXmlCompositeElement.Descendants <PermEnd>().FirstOrDefault();

            openXmlCompositeElement.RemoveAllChildren();

            if (start != null)
            {
                openXmlCompositeElement.AppendChild(start);
            }

            foreach (var newChild in newChildren)
            {
                openXmlCompositeElement.AppendChild(newChild);
            }

            if (end != null)
            {
                openXmlCompositeElement.AppendChild(end);
            }
        }
示例#7
0
        private void ReplaceRuns(OpenXmlCompositeElement par, INodeProvider nodeProvider)
        {
            FixNakedText(par, nodeProvider);

            string text = par.ChildElements.Where(a => nodeProvider.IsRun(a)).ToString(r => nodeProvider.GetText(r), "");

            var matches = TemplateUtils.KeywordsRegex.Matches(text).Cast <Match>().ToList();

            if (matches.Any())
            {
                List <ElementInfo> infos = GetElementInfos(par.ChildElements, nodeProvider);

                par.RemoveAllChildren();

                var stack = new Stack <ElementInfo>(infos.AsEnumerable().Reverse());

                foreach (var m in matches)
                {
                    var interval = new Interval <int>(m.Index, m.Index + m.Length);

                    //  [Before][Start][Ignore][Ignore][End]...[Remaining]
                    //              [        Match       ]

                    ElementInfo start = stack.Pop();           //Start
                    while (start.Interval.Max <= interval.Min) //Before
                    {
                        par.Append(start.Element);
                        start = stack.Pop();
                    }

                    var startRun = (OpenXmlCompositeElement)nodeProvider.CastRun(start.Element);

                    if (start.Interval.Min < interval.Min)
                    {
                        var firstRunPart = nodeProvider.NewRun(
                            (OpenXmlCompositeElement?)nodeProvider.GetRunProperties(startRun)?.CloneNode(true),
                            start.Text !.Substring(0, m.Index - start.Interval.Min),
                            SpaceProcessingModeValues.Preserve
                            );
                        par.Append(firstRunPart);
                    }

                    par.Append(new MatchNode(nodeProvider, m)
                    {
                        RunProperties = (OpenXmlCompositeElement?)nodeProvider.GetRunProperties(startRun)?.CloneNode(true)
                    });

                    ElementInfo end = start;
                    while (end.Interval.Max < interval.Max) //Ignore
                    {
                        end = stack.Pop();
                    }

                    if (interval.Max < end.Interval.Max) //End
                    {
                        var endRun = (OpenXmlCompositeElement)end.Element;

                        var textPart   = end.Text !.Substring(interval.Max - end.Interval.Min);
                        var endRunPart = nodeProvider.NewRun(
                            nodeProvider.GetRunProperties(startRun)?.Let(r => (OpenXmlCompositeElement)r.CloneNode(true)),
                            textPart,
                            SpaceProcessingModeValues.Preserve
                            );

                        stack.Push(new ElementInfo(endRunPart, textPart)
                        {
                            Interval = new Interval <int>(interval.Max, end.Interval.Max)
                        });
                    }
                }

                while (!stack.IsEmpty()) //Remaining
                {
                    var pop = stack.Pop();
                    par.Append(pop.Element);
                }
            }
        }
示例#8
0
        /// <summary>
        /// Sets the SDT content keeping permission elements.
        /// </summary>
        /// <param name="openXmlCompositeElement">The open XML composite element.</param>
        /// <param name="newChildren">The new children.</param>
        private static void SetSdtContentKeepingPermissionElements(OpenXmlCompositeElement openXmlCompositeElement, IEnumerable<Run> newChildren)
        {
            var start = openXmlCompositeElement.Descendants<PermStart>().FirstOrDefault();
            var end = openXmlCompositeElement.Descendants<PermEnd>().FirstOrDefault();
            openXmlCompositeElement.RemoveAllChildren();

            if (start != null)
            {
                openXmlCompositeElement.AppendChild(start);
            }

            foreach (var newChild in newChildren)
            {
                openXmlCompositeElement.AppendChild(newChild);
            }

            if (end != null)
            {
                openXmlCompositeElement.AppendChild(end);
            }
        }
示例#9
0
        /// <summary>
        /// Sets the SDT content keeping permission elements.
        /// </summary>
        /// <param name="openXmlCompositeElement">The open XML composite element.</param>
        /// <param name="newChildren">The new children.</param>
        private void SetSdtContentKeepingPermissionElements(OpenXmlCompositeElement openXmlCompositeElement, List<OpenXmlElement> newChildren)
        {
            PermStart start = openXmlCompositeElement.Descendants<PermStart>().FirstOrDefault();
            PermEnd end = openXmlCompositeElement.Descendants<PermEnd>().FirstOrDefault();
            openXmlCompositeElement.RemoveAllChildren();

            if (start != null)
            {
                openXmlCompositeElement.AppendChild(start);
            }

            foreach (var newChild in newChildren)
            {
                openXmlCompositeElement.AppendChild(newChild);
            }

            if (end != null)
            {
                openXmlCompositeElement.AppendChild(end);
            }
        }