//____________________________________________________________________
        //
        /// <summary>
        /// Apply all the current Html tag to the specified table cell.
        /// </summary>
        public override void ApplyTags(OpenXmlCompositeElement tableCell)
        {
            if (tags.Count > 0)
            {
                TableCellProperties properties = tableCell.GetFirstChild<TableCellProperties>();
                if (properties == null) tableCell.PrependChild<TableCellProperties>(properties = new TableCellProperties());

                var en = tags.GetEnumerator();
                while (en.MoveNext())
                {
                    TagsAtSameLevel tagsOfSameLevel = en.Current.Value.Peek();
                    foreach (OpenXmlElement tag in tagsOfSameLevel.Array)
                        properties.Append(tag.CloneNode(true));
                }
            }

            // Apply some style attributes on the unique Paragraph tag contained inside a table cell.
            if (tagsParagraph.Count > 0)
            {
                Paragraph p = tableCell.GetFirstChild<Paragraph>();
                ParagraphProperties properties = p.GetFirstChild<ParagraphProperties>();
                if (properties == null) p.PrependChild<ParagraphProperties>(properties = new ParagraphProperties());

                var en = tagsParagraph.GetEnumerator();
                while (en.MoveNext())
                {
                    TagsAtSameLevel tagsOfSameLevel = en.Current.Value.Peek();
                    foreach (OpenXmlElement tag in tagsOfSameLevel.Array)
                        properties.Append(tag.CloneNode(true));
                }
            }
        }
        //____________________________________________________________________
        //

        /// <summary>
        /// Apply all the current Html tag to the specified table cell.
        /// </summary>
        public override void ApplyTags(OpenXmlCompositeElement tableCell)
        {
            if (tags.Count > 0)
            {
                TableCellProperties properties = tableCell.GetFirstChild <TableCellProperties>();
                if (properties == null)
                {
                    tableCell.PrependChild <TableCellProperties>(properties = new TableCellProperties());
                }

                var en = tags.GetEnumerator();
                while (en.MoveNext())
                {
                    TagsAtSameLevel tagsOfSameLevel = en.Current.Value.Peek();
                    foreach (OpenXmlElement tag in tagsOfSameLevel.Array)
                    {
                        SetProperties(properties, tag.CloneNode(true));
                    }
                }
            }

            // Apply some style attributes on the unique Paragraph tag contained inside a table cell.
            Paragraph p = tableCell.GetFirstChild <Paragraph>();

            paragraphStyle.ApplyTags(p);
        }
Esempio n. 3
0
        private static void BindSerie(OpenXmlCompositeElement serie, Data.DataRow dataRow, int index)
        {
            serie.Descendants <Charts.Formula>().ToList().ForEach(f => f.Remove());

            serie.GetFirstChild <Charts.Index>().Val = new UInt32Value((uint)index);
            serie.GetFirstChild <Charts.Order>().Val = new UInt32Value((uint)index);

            var setTxt = serie.Descendants <Charts.SeriesText>().SingleEx();

            setTxt.StringReference.Descendants <Charts.NumericValue>().SingleEx().Text = dataRow[0]?.ToString();

            {
                var cat = serie.Descendants <Charts.CategoryAxisData>().SingleEx();
                cat.Descendants <Charts.PointCount>().SingleEx().Val = new UInt32Value((uint)dataRow.Table.Columns.Count - 1);
                var catValues = cat.Descendants <Charts.StringPoint>().ToList();
                SynchronizeNodes(catValues, dataRow.Table.Columns.Cast <Data.DataColumn>().Skip(1).ToList(),
                                 (sp, col, i, isCloned) =>
                {
                    sp.Index = new UInt32Value((uint)i);
                    sp.Descendants <Charts.NumericValue>().Single().Text = col.ColumnName;
                });
            }

            {
                var vals = serie.Descendants <Charts.Values>().SingleEx();
                vals.Descendants <Charts.PointCount>().SingleEx().Val = new UInt32Value((uint)dataRow.Table.Columns.Count - 1);
                var valsValues = vals.Descendants <Charts.NumericPoint>().ToList();
                SynchronizeNodes(valsValues, dataRow.ItemArray.Skip(1).ToList(),
                                 (sp, val, i, isCloned) =>
                {
                    sp.Index = new UInt32Value((uint)i);
                    sp.Descendants <Charts.NumericValue>().Single().Text = ToStringLocal(val);
                });
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Apply all the current Html tag (Run properties) to the specified run.
        /// </summary>
        public override void ApplyTags(OpenXmlCompositeElement run)
        {
            if (tags.Count == 0 && DefaultRunStyle == null)
            {
                return;
            }

            RunProperties properties = run.GetFirstChild <RunProperties>();

            if (properties == null)
            {
                run.PrependChild <RunProperties>(properties = new RunProperties());
            }

            var en = tags.GetEnumerator();

            while (en.MoveNext())
            {
                TagsAtSameLevel tagsOfSameLevel = en.Current.Value.Peek();
                foreach (OpenXmlElement tag in tagsOfSameLevel.Array)
                {
                    SetProperties(properties, tag.CloneNode(true));
                }
            }

            if (this.DefaultRunStyle != null)
            {
                properties.RunStyle = new RunStyle()
                {
                    Val = this.DefaultRunStyle
                }
            }
            ;
        }
        /// <summary>
        /// Apply all the current Html tag (Paragraph properties) to the specified paragrah.
        /// </summary>
        public override void ApplyTags(OpenXmlCompositeElement paragraph)
        {
            if (tags.Count == 0)
            {
                return;
            }

            ParagraphProperties properties = paragraph.GetFirstChild <ParagraphProperties>();

            if (properties == null)
            {
                paragraph.PrependChild <ParagraphProperties>(properties = new ParagraphProperties());
            }

            var en = tags.GetEnumerator();

            while (en.MoveNext())
            {
                TagsAtSameLevel tagsOfSameLevel = en.Current.Value.Peek();
                foreach (OpenXmlElement tag in tagsOfSameLevel.Array)
                {
                    SetProperties(properties, tag.CloneNode(true));
                }
            }
        }
Esempio n. 6
0
    private static void BindSerie(OpenXmlCompositeElement serie, List <Data.DataRow> rows, Data.DataColumn dataColumn, int index)
    {
        serie.Descendants <Charts.Formula>().ToList().ForEach(f => f.Remove());

        serie.GetFirstChild <Charts.Index>() !.Val = new UInt32Value((uint)index);
        serie.GetFirstChild <Charts.Order>() !.Val = new UInt32Value((uint)index);

        var setTxt = serie.Descendants <Charts.SeriesText>().SingleEx();

        setTxt.StringReference !.Descendants <Charts.NumericValue>().SingleEx().Text = dataColumn.ColumnName;

        {
            var cat = serie.Descendants <Charts.CategoryAxisData>().SingleEx();
            cat.Descendants <Charts.PointCount>().SingleEx().Val = new UInt32Value((uint)rows.Count);
            if (cat.Descendants <Charts.StringPoint>().ToList() is { Count : > 0 } strPoints)
            {
                SynchronizeNodes(strPoints, rows,
                                 (sp, row, i, isCloned) =>
                {
                    sp.Index = new UInt32Value((uint)i);
                    sp.Descendants <Charts.NumericValue>().Single().Text = ToExcelString(row[0]) !;
                });
            }
        /// <summary>
        /// Apply all the current Html tag (Paragraph properties) to the specified paragrah.
        /// </summary>
        public override void ApplyTags(OpenXmlCompositeElement paragraph)
        {
            if (tags.Count == 0) return;

            ParagraphProperties properties = paragraph.GetFirstChild<ParagraphProperties>();
            if (properties == null) paragraph.PrependChild<ParagraphProperties>(properties = new ParagraphProperties());

            var en = tags.GetEnumerator();
            while (en.MoveNext())
            {
                TagsAtSameLevel tagsOfSameLevel = en.Current.Value.Peek();
                foreach (OpenXmlElement tag in tagsOfSameLevel.Array)
                    properties.Append(tag.CloneNode(true));
            }
        }
        public override IShape Create(OpenXmlCompositeElement pShapeTreeChild, SCSlide slide)
        {
            if (pShapeTreeChild is P.GraphicFrame pGraphicFrame)
            {
                A.GraphicData aGraphicData = pShapeTreeChild.GetFirstChild <A.Graphic>().GetFirstChild <A.GraphicData>();
                if (aGraphicData.Uri.Value.Equals(Uri, StringComparison.Ordinal))
                {
                    SlideChart chart = new(pGraphicFrame, slide);

                    return(chart);
                }
            }

            return(Successor?.Create(pShapeTreeChild, slide));
        }
Esempio n. 9
0
        private void AssertIsHr(OpenXmlCompositeElement hr, bool expectSpacing)
        {
            Assert.Equal(2, hr.ChildElements.Count);
            var props = hr.GetFirstChild <ParagraphProperties>();

            Assert.NotNull(props);

            Assert.Equal(props.ChildElements.Count, expectSpacing? 2:1);
            Assert.NotNull(props.ParagraphBorders);
            Assert.NotNull(props.ParagraphBorders.TopBorder);

            if (expectSpacing)
            {
                Assert.NotNull(props.SpacingBetweenLines);
            }
        }
Esempio n. 10
0
        public override IShape Create(OpenXmlCompositeElement pShapeTreeChild, SCSlide slide)
        {
            if (pShapeTreeChild is P.GraphicFrame pGraphicFrame)
            {
                var grData = pShapeTreeChild.GetFirstChild <A.Graphic>().GetFirstChild <A.GraphicData>();
                if (grData.Uri.Value.Equals(Uri, StringComparison.Ordinal))
                {
                    var spContext      = _shapeContextBuilder.Build(pShapeTreeChild);
                    var innerTransform = _transformFactory.FromComposite(pGraphicFrame);
                    var oleObject      = new SlideOLEObject(pGraphicFrame, spContext, slide);

                    return(oleObject);
                }
            }

            return(Successor?.Create(pShapeTreeChild, slide));
        }
Esempio n. 11
0
        private void AssertIsHr(OpenXmlCompositeElement hr, bool expectSpacing)
        {
            Assert.Multiple(() => {
                Assert.That(hr.ChildElements.Count, Is.EqualTo(2));
                var props = hr.GetFirstChild <ParagraphProperties>();
                Assert.IsNotNull(props);

                Assert.That(props.ChildElements.Count, Is.EqualTo(expectSpacing? 2:1));
                Assert.IsNotNull(props.ParagraphBorders);
                Assert.IsNotNull(props.ParagraphBorders.TopBorder);

                if (expectSpacing)
                {
                    Assert.IsNotNull(props.SpacingBetweenLines);
                }
            });
        }
Esempio n. 12
0
        /// <summary>
        /// Apply all the current Html tag (Run properties) to the specified run.
        /// </summary>
        public override void ApplyTags(OpenXmlCompositeElement run)
        {
            if (tags.Count == 0 && DefaultRunStyle == null) return;

            RunProperties properties = run.GetFirstChild<RunProperties>();
            if (properties == null) run.PrependChild<RunProperties>(properties = new RunProperties());

            var en = tags.GetEnumerator();
            while (en.MoveNext())
            {
                TagsAtSameLevel tagsOfSameLevel = en.Current.Value.Peek();
                foreach (OpenXmlElement tag in tagsOfSameLevel.Array)
                    properties.Append(tag.CloneNode(true));
            }

            if (this.DefaultRunStyle != null)
                properties.Append(new RunStyle() { Val = this.DefaultRunStyle });
        }
Esempio n. 13
0
        private void AssertIsImg(OpenXmlCompositeElement elements)
        {
            var run = elements.GetFirstChild <Run>();

            Assert.IsNotNull(run);
            var img = run.GetFirstChild <Drawing>();

            Assert.IsNotNull(img);
            Assert.IsNotNull(img.Inline?.Graphic?.GraphicData);
            var pic = img.Inline.Graphic.GraphicData.GetFirstChild <pic.Picture>();

            Assert.IsNotNull(pic?.BlipFill?.Blip?.Embed);

            var imagePartId = pic.BlipFill.Blip.Embed.Value;
            var part        = mainPart.GetPartById(imagePartId);

            Assert.That(part, Is.TypeOf(typeof(ImagePart)));
        }