示例#1
0
        /**
         * Ensure that the specified paragraph has a reference marker for this
         * footnote by adding a footnote reference if one is not found.
         * <p>This method is for the first paragraph in the footnote, not
         * paragraphs that will refer to the footnote. For references to
         * the footnote, use {@link XWPFParagraph#addFootnoteReference(XWPFFootnote)}.
         * </p>
         * <p>The first run of the first paragraph in a footnote should
         * contain a {@link CTFtnEdnRef} object.</p>
         *
         * @param p The {@link XWPFParagraph} to ensure
         */
        public void EnsureFootnoteRef(XWPFParagraph p)
        {
            XWPFRun r = null;

            if (p.Runs.Count > 0)
            {
                r = p.Runs[0];
            }
            if (r == null)
            {
                r = p.CreateRun();
            }
            CT_R ctr      = r.GetCTR();
            bool foundRef = false;

            foreach (CT_FtnEdnRef reference in ctr.GetFootnoteReferenceList())
            {
                if (Id.ToString().Equals(reference.id))
                {
                    foundRef = true;
                    break;
                }
            }
            if (!foundRef)
            {
                ctr.AddNewRPr().AddNewRStyle().val = "FootnoteReference";
                ctr.AddNewFootnoteRef();
            }
        }
示例#2
0
        public void TestAddFootnoteRefToParagraph()
        {
            XWPFParagraph p    = docOut.CreateParagraph();
            var           runs = p.Runs;

            Assert.AreEqual(0, runs.Count, "Expected no runs in new paragraph");
            p.AddFootnoteReference(footnote);
            XWPFRun run = p.Runs[0];
            CT_R    ctr = run.GetCTR();

            Assert.IsNotNull(run, "Expected a run");
            CT_FtnEdnRef ref1 = ctr.GetFootnoteReferenceList()[0];

            Assert.IsNotNull(ref1);
            Assert.AreEqual(footnote.Id.ToString(), ref1.id, "Footnote ID and reference ID did not match");
        }