Exemplo n.º 1
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 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 (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));
                }
            }
        }
        //____________________________________________________________________
        //

        /// <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);
        }
        /// <summary>
        ///A test for PrependChild
        ///</summary>
        public void PrependChildTestHelper <T>()
            where T : OpenXmlElement
        {
            OpenXmlCompositeElement target = CreateOpenXmlCompositeElement();
            T newChild = default(T);
            T expected = default(T);
            T actual;

            actual = target.PrependChild <T>(newChild);
            Assert.Equal(expected, actual);
        }
Exemplo n.º 6
0
        //
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for PrependChild
        ///</summary>
        public void PrependChildTestHelper <T>()
            where T : OpenXmlElement
        {
            OpenXmlCompositeElement target = CreateOpenXmlCompositeElement(); // TODO: Initialize to an appropriate value
            T newChild = default(T);                                          // TODO: Initialize to an appropriate value
            T expected = default(T);                                          // TODO: Initialize to an appropriate value
            T actual;

            actual = target.PrependChild <T>(newChild);
            Assert.Equal(expected, actual);
            //Assert.Inconclusive("Verify the correctness of this test method.");
        }
        /// <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));
            }
        }
Exemplo n.º 8
0
        internal static T GetOrCreate <T>(this OpenXmlCompositeElement element, bool prepend) where T : OpenXmlElement, new()
        {
            if (!element.Has <T>())
            {
                if (prepend)
                {
                    element.PrependChild(new T());
                }
                else
                {
                    element.AppendChild(new T());
                }
            }

            return(element.Elements <T>().First());
        }
Exemplo n.º 9
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 });
        }