示例#1
0
        public void TestCreate()
        {
            XWPFDocument doc = new XWPFDocument();

            Assert.AreEqual(null, doc.GetHeaderFooterPolicy());
            Assert.AreEqual(0, doc.HeaderList.Count);
            Assert.AreEqual(0, doc.FooterList.Count);

            XWPFHeaderFooterPolicy policy = doc.CreateHeaderFooterPolicy();

            Assert.IsNotNull(doc.GetHeaderFooterPolicy());
            Assert.AreEqual(0, doc.HeaderList.Count);
            Assert.AreEqual(0, doc.FooterList.Count);

            // Create a header and a footer
            XWPFHeader header = policy.CreateHeader(XWPFHeaderFooterPolicy.DEFAULT);
            XWPFFooter footer = policy.CreateFooter(XWPFHeaderFooterPolicy.DEFAULT);

            header.CreateParagraph().CreateRun().SetText("Header Hello");
            footer.CreateParagraph().CreateRun().SetText("Footer Bye");


            // Save, re-load, and check
            doc = XWPFTestDataSamples.WriteOutAndReadBack(doc);
            Assert.IsNotNull(doc.GetHeaderFooterPolicy());
            Assert.AreEqual(1, doc.HeaderList.Count);
            Assert.AreEqual(1, doc.FooterList.Count);

            Assert.AreEqual("Header Hello\n", doc.HeaderList[(0)].Text);
            Assert.AreEqual("Footer Bye\n", doc.FooterList[(0)].Text);
        }
示例#2
0
        public void TestCreateHeaderPicture()
        { // TODO Fix
            XWPFDocument doc = new XWPFDocument();

            // Starts with no header
            XWPFHeaderFooterPolicy policy = doc.GetHeaderFooterPolicy();

            Assert.IsNull(policy);

            // Add a default header
            policy = doc.CreateHeaderFooterPolicy();

            XWPFHeader header = policy.CreateHeader(XWPFHeaderFooterPolicy.DEFAULT);

            header.Paragraphs[0].CreateRun().SetText("Hello, Header World!");
            header.CreateParagraph().CreateRun().SetText("Paragraph 2");
            Assert.AreEqual(0, header.AllPictures.Count);
            Assert.AreEqual(2, header.Paragraphs.Count);

            // Add a picture to  the first paragraph
            header.Paragraphs[0].Runs[0].AddPicture(
                new ByteArrayInputStream(new byte[] { 1, 2, 3, 4 }),
                (int)PictureType.JPEG, "test.jpg", 2, 2);

            // Check
            verifyOneHeaderPicture(doc);

            // Save, re-load, re-check
            XWPFDocument readBack = XWPFTestDataSamples.WriteOutAndReadBack(doc);

            verifyOneHeaderPicture(readBack);
        }
示例#3
0
        static void Main(string[] args)
        {
            XWPFDocument  doc       = new XWPFDocument();
            XWPFParagraph paragraph = doc.CreateParagraph();
            XWPFRun       run       = paragraph.CreateRun();

            run.SetText("The Body:");
            var hfPolicy = doc.CreateHeaderFooterPolicy();

            hfPolicy.CreateWatermark("My Watermark");


            using (FileStream fs = new FileStream("watermark.docx", FileMode.Create))
            {
                doc.Write(fs);
            }
        }