Exemple #1
0
        internal override async Task Write(XWPFDocument doc)
        {
            var para = doc.CreateParagraph();
            var run  = para.CreateRun();

            run.FontFamily = "Arial";
            run.FontSize   = 12;
            run.SetText(this.RawText);

            if (Children.Any())
            {
                var numbering = doc.CreateNumbering();
                numberingId = numbering.AddNum("1");
            }

            await WriteChildren(doc);
        }
Exemple #2
0
        public void TestAddNumberingToDoc()
        {
            string abstractNumId = "1";
            string numId         = "1";

            XWPFDocument  docOut    = new XWPFDocument();
            XWPFNumbering numbering = docOut.CreateNumbering();

            numId = numbering.AddNum(abstractNumId);

            XWPFDocument docIn = XWPFTestDataSamples.WriteOutAndReadBack(docOut);

            numbering = docIn.GetNumbering();
            Assert.IsTrue(numbering.NumExist(numId));
            XWPFNum num = numbering.GetNum(numId);

            string CompareAbstractNum = num.GetCTNum().abstractNumId.val;

            Assert.AreEqual(abstractNumId, CompareAbstractNum);
        }
Exemple #3
0
        public void TestOverrideList()
        {
            //TODO: for now the try/catch block ensures loading/inclusion of CTNumLevel
            //for down stream Processing.
            //Ideally, we should find files that actually use overrides and test against those.
            //Use XWPFParagraph's GetNumStartOverride() in the actual tests

            XWPFDocument  doc = XWPFTestDataSamples.OpenSampleDocument("Numbering.docx");
            XWPFParagraph p = doc.Paragraphs[(18)]; XWPFNumbering numbering = doc.CreateNumbering();
            bool          ex = false;

            Assert.IsNull(p.GetNumStartOverride());
            try
            {
                numbering.GetNum(p.GetNumID()).GetCTNum().GetLvlOverrideArray(1);
            }
            catch (ArgumentOutOfRangeException e)
            {
                ex = true;
            }
            Assert.IsTrue(ex);
        }
        static void Main(string[] args)
        {
            XWPFDocument doc = new XWPFDocument();

            // Single level bullet.
            XWPFNumbering numbering = doc.CreateNumbering();

            string abstractNumId = numbering.AddAbstractNum();
            string numId         = numbering.AddNum(abstractNumId);

            XWPFParagraph p0 = doc.CreateParagraph();
            XWPFRun       r0 = p0.CreateRun();

            r0.SetText("simple bullet");
            r0.IsBold     = true;
            r0.FontFamily = "Courier";
            r0.FontSize   = 12;

            XWPFParagraph p1 = doc.CreateParagraph();
            XWPFRun       r1 = p1.CreateRun();

            r1.SetText("first, create paragraph and run, set text");
            p1.SetNumID(numId);

            XWPFParagraph p2 = doc.CreateParagraph();
            XWPFRun       r2 = p2.CreateRun();

            r2.SetText("second, call XWPFDocument.CreateNumbering() to create numbering");
            p2.SetNumID(numId);

            XWPFParagraph p3 = doc.CreateParagraph();
            XWPFRun       r3 = p3.CreateRun();

            r3.SetText("third, add AbstractNum[numbering.AddAbstractNum()] and Num(numbering.AddNum(abstractNumId))");
            p3.SetNumID(numId);

            XWPFParagraph p4 = doc.CreateParagraph();
            XWPFRun       r4 = p4.CreateRun();

            r4.SetText("next, call XWPFParagraph.SetNumID(numId) to set paragraph property, CT_P.pPr.numPr");
            p4.SetNumID(numId);

            // Multi level bullet.
            abstractNumId = numbering.AddAbstractNum();
            numId         = numbering.AddNum(abstractNumId);
            doc.CreateParagraph();
            doc.CreateParagraph();

            p1 = doc.CreateParagraph();
            r1 = p1.CreateRun();
            r1.SetText("multi level bullet");
            r1.IsBold     = true;
            r1.FontFamily = "Courier";
            r1.FontSize   = 12;

            p1 = doc.CreateParagraph();
            r1 = p1.CreateRun();
            r1.SetText("first");
            p1.SetNumID(numId, "0");
            p1 = doc.CreateParagraph();
            r1 = p1.CreateRun();
            r1.SetText("first-first");
            p1.SetNumID(numId, "1");
            p1 = doc.CreateParagraph();
            r1 = p1.CreateRun();
            r1.SetText("first-second");
            p1.SetNumID(numId, "1");
            p1 = doc.CreateParagraph();
            r1 = p1.CreateRun();
            r1.SetText("first-third");
            p1.SetNumID(numId, "1");
            p1 = doc.CreateParagraph();
            r1 = p1.CreateRun();
            r1.SetText("second");
            p1.SetNumID(numId, "0");
            p1 = doc.CreateParagraph();
            r1 = p1.CreateRun();
            r1.SetText("second-first");
            p1.SetNumID(numId, "1");
            p1 = doc.CreateParagraph();
            r1 = p1.CreateRun();
            r1.SetText("second-second");
            p1.SetNumID(numId, "1");
            p1 = doc.CreateParagraph();
            r1 = p1.CreateRun();
            r1.SetText("second-third");
            p1.SetNumID(numId, "1");
            p1 = doc.CreateParagraph();
            r1 = p1.CreateRun();
            r1.SetText("second-third-first");
            p1.SetNumID(numId, "2");
            p1 = doc.CreateParagraph();
            r1 = p1.CreateRun();
            r1.SetText("second-third-second");
            p1.SetNumID(numId, "2");
            p1 = doc.CreateParagraph();
            r1 = p1.CreateRun();
            r1.SetText("third");
            p1.SetNumID(numId, "0");

            using (FileStream sw = new FileStream("CreateBulletNPOI.docx", FileMode.Create))
            {
                doc.Write(sw);
            }
        }
Exemple #5
0
        public void Main()
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            XWPFDocument doc = new XWPFDocument();
            //simple bullet
            XWPFNumbering numbering = doc.CreateNumbering();

            string abstractNumId = numbering.AddAbstractNum();
            string numId         = numbering.AddNum(abstractNumId);

            XWPFParagraph p0 = doc.CreateParagraph();
            XWPFRun       r0 = p0.CreateRun();

            r0.SetText("simple bullet");
            r0.IsBold     = true;
            r0.FontFamily = "Courier";
            r0.FontSize   = 12;

            XWPFParagraph p1 = doc.CreateParagraph();
            XWPFRun       r1 = p1.CreateRun();

            r1.SetText("first, create paragraph and run, set text");
            p1.SetNumID(numId);

            XWPFParagraph p2 = doc.CreateParagraph();
            XWPFRun       r2 = p2.CreateRun();

            r2.SetText("second, call XWPFDocument.CreateNumbering() to create numbering");
            p2.SetNumID(numId);

            XWPFParagraph p3 = doc.CreateParagraph();
            XWPFRun       r3 = p3.CreateRun();

            r3.SetText("third, add AbstractNum[numbering.AddAbstractNum()] and Num(numbering.AddNum(abstractNumId))");
            p3.SetNumID(numId);

            XWPFParagraph p4 = doc.CreateParagraph();
            XWPFRun       r4 = p4.CreateRun();

            r4.SetText("next, call XWPFParagraph.SetNumID(numId) to set paragraph property, CT_P.pPr.numPr");
            p4.SetNumID(numId);

            //multi level
            abstractNumId = numbering.AddAbstractNum();
            numId         = numbering.AddNum(abstractNumId);
            doc.CreateParagraph();
            doc.CreateParagraph();

            p1 = doc.CreateParagraph();
            r1 = p1.CreateRun();
            r1.SetText("multi level bullet");
            //r1.SetBold(true);
            r1.IsBold     = true;
            r1.FontFamily = "Courier";
            r1.FontSize   = 12;

            p1 = doc.CreateParagraph();
            r1 = p1.CreateRun();
            r1.SetText("first");
            p1.SetNumID(numId, "0");
            p1 = doc.CreateParagraph();
            r1 = p1.CreateRun();
            r1.SetText("first-first");
            p1.SetNumID(numId, "1");
            p1 = doc.CreateParagraph();
            r1 = p1.CreateRun();
            r1.SetText("first-second");
            p1.SetNumID(numId, "1");
            p1 = doc.CreateParagraph();
            r1 = p1.CreateRun();
            r1.SetText("first-third");
            p1.SetNumID(numId, "1");
            p1 = doc.CreateParagraph();
            r1 = p1.CreateRun();
            r1.SetText("second");
            p1.SetNumID(numId, "0");
            p1 = doc.CreateParagraph();
            r1 = p1.CreateRun();
            r1.SetText("second-first");
            p1.SetNumID(numId, "1");
            p1 = doc.CreateParagraph();
            r1 = p1.CreateRun();
            r1.SetText("second-second");
            p1.SetNumID(numId, "1");
            p1 = doc.CreateParagraph();
            r1 = p1.CreateRun();
            r1.SetText("second-third");
            p1.SetNumID(numId, "1");
            p1 = doc.CreateParagraph();
            r1 = p1.CreateRun();
            r1.SetText("second-third-first");
            p1.SetNumID(numId, "2");
            p1 = doc.CreateParagraph();
            r1 = p1.CreateRun();
            r1.SetText("second-third-second");
            p1.SetNumID(numId, "2");
            p1 = doc.CreateParagraph();
            r1 = p1.CreateRun();
            r1.SetText("third");
            p1.SetNumID(numId, "0");

            FileStream sw = new FileStream("bullet-sample.docx", FileMode.Create);

            doc.Write(sw);
            sw.Close();
        }