Пример #1
0
        public void Create()
        {
            //ExStart
            //ExFor:HeaderFooter
            //ExFor:HeaderFooter.#ctor(DocumentBase, HeaderFooterType)
            //ExFor:HeaderFooter.HeaderFooterType
            //ExFor:HeaderFooter.IsHeader
            //ExFor:HeaderFooterCollection
            //ExFor:Paragraph.IsEndOfHeaderFooter
            //ExFor:Paragraph.ParentSection
            //ExFor:Paragraph.ParentStory
            //ExFor:Story.AppendParagraph
            //ExSummary:Shows how to create a header and a footer.
            Document doc = new Document();

            // Create a header and append a paragraph to it. The text in that paragraph
            // will appear at the top of every page of this section, above the main body text.
            HeaderFooter header = new HeaderFooter(doc, HeaderFooterType.HeaderPrimary);

            doc.FirstSection.HeadersFooters.Add(header);

            Paragraph para = header.AppendParagraph("My header.");

            Assert.True(header.IsHeader);
            Assert.True(para.IsEndOfHeaderFooter);

            // Create a footer and append a paragraph to it. The text in that paragraph
            // will appear at the bottom of every page of this section, below the main body text.
            HeaderFooter footer = new HeaderFooter(doc, HeaderFooterType.FooterPrimary);

            doc.FirstSection.HeadersFooters.Add(footer);

            para = footer.AppendParagraph("My footer.");

            Assert.False(footer.IsHeader);
            Assert.True(para.IsEndOfHeaderFooter);

            Assert.AreEqual(footer, para.ParentStory);
            Assert.AreEqual(footer.ParentSection, para.ParentSection);
            Assert.AreEqual(footer.ParentSection, header.ParentSection);

            doc.Save(ArtifactsDir + "HeaderFooter.Create.docx");
            //ExEnd

            doc = new Document(ArtifactsDir + "HeaderFooter.Create.docx");

            Assert.True(doc.FirstSection.HeadersFooters[HeaderFooterType.HeaderPrimary].Range.Text
                        .Contains("My header."));
            Assert.True(doc.FirstSection.HeadersFooters[HeaderFooterType.FooterPrimary].Range.Text
                        .Contains("My footer."));
        }
Пример #2
0
        public void HeaderFooterCreate()
        {
            //ExStart
            //ExFor:HeaderFooter
            //ExFor:HeaderFooter.#ctor(DocumentBase, HeaderFooterType)
            //ExFor:HeaderFooter.HeaderFooterType
            //ExFor:HeaderFooter.IsHeader
            //ExFor:HeaderFooterCollection
            //ExFor:Paragraph.IsEndOfHeaderFooter
            //ExFor:Paragraph.ParentSection
            //ExFor:Paragraph.ParentStory
            //ExFor:Story.AppendParagraph
            //ExSummary:Creates a header and footer using the document object model and insert them into a section.
            Document doc = new Document();

            HeaderFooter header = new HeaderFooter(doc, HeaderFooterType.HeaderPrimary);

            doc.FirstSection.HeadersFooters.Add(header);

            // Add a paragraph with text to the footer
            Paragraph para = header.AppendParagraph("My header");

            Assert.True(header.IsHeader);
            Assert.True(para.IsEndOfHeaderFooter);

            HeaderFooter footer = new HeaderFooter(doc, HeaderFooterType.FooterPrimary);

            doc.FirstSection.HeadersFooters.Add(footer);

            // Add a paragraph with text to the footer
            para = footer.AppendParagraph("My footer");

            Assert.False(footer.IsHeader);
            Assert.True(para.IsEndOfHeaderFooter);

            Assert.AreEqual(footer, para.ParentStory);
            Assert.AreEqual(footer.ParentSection, para.ParentSection);
            Assert.AreEqual(footer.ParentSection, header.ParentSection);

            doc.Save(ArtifactsDir + "HeaderFooter.HeaderFooterCreate.docx");
            //ExEnd

            doc = new Document(ArtifactsDir + "HeaderFooter.HeaderFooterCreate.docx");

            Assert.True(doc.FirstSection.HeadersFooters[HeaderFooterType.HeaderPrimary].Range.Text
                        .Contains("My header"));
            Assert.True(doc.FirstSection.HeadersFooters[HeaderFooterType.FooterPrimary].Range.Text
                        .Contains("My footer"));
        }
        public void CreateFooter()
        {
            //ExStart
            //ExFor:HeaderFooter
            //ExFor:HeaderFooter.#ctor(DocumentBase, HeaderFooterType)
            //ExFor:HeaderFooterCollection
            //ExFor:Story.AppendParagraph
            //ExSummary:Creates a footer using the document object model and inserts it into a section.
            Document doc = new Document();

            HeaderFooter footer = new HeaderFooter(doc, HeaderFooterType.FooterPrimary);
            doc.FirstSection.HeadersFooters.Add(footer);

            // Add a paragraph with text to the footer.
            footer.AppendParagraph("TEST FOOTER");

            doc.Save(MyDir + @"\Artifacts\HeaderFooter.CreateFooter.doc");
            //ExEnd

            doc = new Document(MyDir + @"\Artifacts\HeaderFooter.CreateFooter.doc");
            Assert.True(doc.FirstSection.HeadersFooters[HeaderFooterType.FooterPrimary].Range.Text.Contains("TEST FOOTER"));
        }
Пример #4
0
        public void CreateFooter()
        {
            //ExStart
            //ExFor:HeaderFooter
            //ExFor:HeaderFooter.#ctor(DocumentBase, HeaderFooterType)
            //ExFor:HeaderFooterCollection
            //ExFor:Story.AppendParagraph
            //ExSummary:Creates a footer using the document object model and inserts it into a section.
            Document doc = new Document();

            HeaderFooter footer = new HeaderFooter(doc, HeaderFooterType.FooterPrimary);

            doc.FirstSection.HeadersFooters.Add(footer);

            // Add a paragraph with text to the footer.
            footer.AppendParagraph("TEST FOOTER");

            doc.Save(MyDir + @"\Artifacts\HeaderFooter.CreateFooter.doc");
            //ExEnd

            Assert.True(doc.FirstSection.HeadersFooters[HeaderFooterType.FooterPrimary].Range.Text.Contains("TEST FOOTER"));
        }
Пример #5
0
        public void SectionDeleteHeaderFooterShapes()
        {
            //ExStart
            //ExFor:Section.DeleteHeaderFooterShapes
            //ExSummary:Removes all images and shapes from all headers footers in a section.
            Document     doc         = new Document();
            Section      section     = doc.Sections[0];
            HeaderFooter firstHeader = new HeaderFooter(doc, HeaderFooterType.HeaderFirst);

            section.HeadersFooters.Add(firstHeader);

            firstHeader.AppendParagraph("This paragraph contains a shape: ");

            Shape shape = new Shape(doc, ShapeType.Arrow);

            firstHeader.FirstParagraph.AppendChild(shape);

            Assert.AreEqual(1, firstHeader.GetChildNodes(NodeType.Shape, true).Count);

            section.DeleteHeaderFooterShapes();

            Assert.AreEqual(0, firstHeader.GetChildNodes(NodeType.Shape, true).Count);
            //ExEnd
        }