Exemplo n.º 1
0
        public XWPFFootnote AddEndnote(CT_FtnEdn note)
        {
            XWPFFootnote xwpfFootnote = new XWPFFootnote(this, note);

            this.endnotes.Add(int.Parse(note.id), xwpfFootnote);
            return(xwpfFootnote);
        }
Exemplo n.º 2
0
        public XWPFFootnote AddFootnote(CT_FtnEdn note)
        {
            CT_FtnEdn note1 = this.ctFootnotes.AddNewFootnote();

            note1.Set(note);
            XWPFFootnote xwpfFootnote = new XWPFFootnote(note1, this);

            this.listFootnote.Add(xwpfFootnote);
            return(xwpfFootnote);
        }
Exemplo n.º 3
0
        /**
         * add a footnote to the document
         * @param note
         * @throws IOException
         */
        public XWPFFootnote AddFootnote(CT_FtnEdn note)
        {
            CT_FtnEdn newNote = ctFootnotes.AddNewFootnote();

            newNote.Set(note);
            XWPFFootnote xNote = new XWPFFootnote(newNote, this);

            listFootnote.Add(xNote);
            return(xNote);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Create a new footnote and add it to the document.
        /// </summary>
        /// <remarks>
        /// The new note will have one paragraph with the style "FootnoteText"
        /// and one run containing the required footnote reference with the
        /// style "FootnoteReference".
        /// </remarks>
        /// <returns>New XWPFFootnote</returns>
        public XWPFFootnote CreateFootnote()
        {
            CT_FtnEdn newNote = new CT_FtnEdn();

            newNote.type = ST_FtnEdn.normal;

            XWPFFootnote footnote = AddFootnote(newNote);
            int          id       = ctFootnotes.SizeOfFootnoteArray;

            footnote.GetCTFtnEdn().id = id;
            return(footnote);
        }
Exemplo n.º 5
0
        public void TestAddFootnotesToDocument()
        {
            XWPFDocument docOut = new XWPFDocument();

            int noteId = 1;

            XWPFFootnotes footnotes = docOut.CreateFootnotes();
            CT_FtnEdn     ctNote    = new CT_FtnEdn();

            ctNote.id   = (noteId.ToString());
            ctNote.type = (ST_FtnEdn.normal);
            footnotes.AddFootnote(ctNote);

            XWPFDocument docIn = XWPFTestDataSamples.WriteOutAndReadBack(docOut);

            XWPFFootnote note = docIn.GetFootnoteByID(noteId);

            Assert.AreEqual(note.GetCTFtnEdn().type, ST_FtnEdn.normal);
        }
Exemplo n.º 6
0
 public XWPFParagraph(CT_P prgrph, IBody part)
 {
     this.paragraph = prgrph;
     this.part      = part;
     this.document  = part.GetXWPFDocument();
     if (this.document == null)
     {
         throw new NullReferenceException();
     }
     this.Runs = new List <XWPFRun>();
     this.BuildRunsInOrderFromXml(this.paragraph.Items);
     foreach (XWPFRun run in this.Runs)
     {
         CT_R ctr = run.GetCTR();
         if (this.document != null)
         {
             foreach (object obj in ctr.Items)
             {
                 if (obj is CT_FtnEdnRef)
                 {
                     CT_FtnEdnRef ctFtnEdnRef = (CT_FtnEdnRef)obj;
                     this.footnoteText.Append("[").Append(ctFtnEdnRef.id).Append(": ");
                     XWPFFootnote xwpfFootnote = this.document.GetFootnoteByID(int.Parse(ctFtnEdnRef.id)) ?? this.document.GetEndnoteByID(int.Parse(ctFtnEdnRef.id));
                     bool         flag         = true;
                     foreach (XWPFParagraph paragraph in (IEnumerable <XWPFParagraph>)xwpfFootnote.Paragraphs)
                     {
                         if (!flag)
                         {
                             this.footnoteText.Append("\n");
                             flag = false;
                         }
                         this.footnoteText.Append(paragraph.GetText());
                     }
                     this.footnoteText.Append("]");
                 }
             }
         }
     }
 }
Exemplo n.º 7
0
 public void AddFootnote(XWPFFootnote footnote)
 {
     this.listFootnote.Add(footnote);
     this.ctFootnotes.AddNewFootnote().Set(footnote.GetCTFtnEdn());
 }
Exemplo n.º 8
0
        public XWPFParagraph(CT_P prgrph, IBody part)
        {
            this.paragraph = prgrph;
            this.part      = part;

            this.document = part.GetXWPFDocument();

            if (document == null)
            {
                throw new NullReferenceException();
            }
            // Build up the character runs
            runs = new List <XWPFRun>();

            BuildRunsInOrderFromXml(paragraph.Items);
            // Look for bits associated with the runs
            foreach (XWPFRun run in runs)
            {
                CT_R r = run.GetCTR();
                if (document != null)
                {
                    for (int i = 0; i < r.Items.Count; i++)
                    {
                        object o = r.Items[i];
                        if (o is CT_FtnEdnRef)
                        {
                            CT_FtnEdnRef ftn = (CT_FtnEdnRef)o;
                            footnoteText.Append("[").Append(ftn.id).Append(": ");

                            XWPFFootnote footnote = null;

                            if (r.ItemsElementName.Count > i && r.ItemsElementName[i] == RunItemsChoiceType.endnoteReference)
                            {
                                footnote = document.GetEndnoteByID(int.Parse(ftn.id));
                                if (footnote == null)
                                {
                                    footnote = document.GetFootnoteByID(int.Parse(ftn.id));
                                }
                            }
                            else
                            {
                                footnote = document.GetFootnoteByID(int.Parse(ftn.id));
                                if (footnote == null)
                                {
                                    footnote = document.GetEndnoteByID(int.Parse(ftn.id));
                                }
                            }

                            if (footnote != null)
                            {
                                bool first = true;
                                foreach (XWPFParagraph p in footnote.Paragraphs)
                                {
                                    if (!first)
                                    {
                                        footnoteText.Append("\n");
                                        first = false;
                                    }
                                    footnoteText.Append(p.Text);
                                }
                            }

                            footnoteText.Append("]");
                        }
                    }
                }
            }

            // Get all our child nodes in order, and process them
            //  into XWPFRuns where we can

            /*XmlCursor c = paragraph.NewCursor();
             * c.SelectPath("child::*");
             * while (c.ToNextSelection()) {
             * XmlObject o = c.Object;
             * if(o is CT_R) {
             *    Runs.Add(new XWPFRun((CT_R)o, this));
             * }
             * if(o is CT_Hyperlink) {
             *    CT_Hyperlink link = (CT_Hyperlink)o;
             *    foreach(CTR r in link.RList) {
             *       Runs.Add(new XWPFHyperlinkRun(link, r, this));
             *    }
             * }
             * if(o is CT_SdtRun) {
             *    CT_SdtContentRun run = ((CT_SdtRun)o).SdtContent;
             *    foreach(CTR r in Run.RList) {
             *       Runs.Add(new XWPFRun(r, this));
             *    }
             * }
             * if(o is CT_RunTrackChange) {
             *    foreach(CTR r in ((CT_RunTrackChange)o).RList) {
             *       Runs.Add(new XWPFRun(r, this));
             *    }
             * }
             * if(o is CT_SimpleField) {
             *    foreach(CTR r in ((CT_SimpleField)o).RList) {
             *       Runs.Add(new XWPFRun(r, this));
             *    }
             * }
             * }*/
        }
Exemplo n.º 9
0
        public XWPFParagraph(CT_P prgrph, IBody part)
        {
            this.paragraph = prgrph;
            this.part      = part;

            this.document = part.GetXWPFDocument();

            if (document == null)
            {
                throw new NullReferenceException();
            }
            // Build up the character runs
            runs  = new List <XWPFRun>();
            iRuns = new List <IRunElement>();

            BuildRunsInOrderFromXml(paragraph.Items);
            // Look for bits associated with the runs
            foreach (XWPFRun run in runs)
            {
                CT_R r = run.GetCTR();
                if (document != null)
                {
                    for (int i = 0; i < r.Items.Count; i++)
                    {
                        object o = r.Items[i];
                        if (o is CT_FtnEdnRef)
                        {
                            CT_FtnEdnRef ftn = (CT_FtnEdnRef)o;
                            footnoteText.Append("[").Append(ftn.id).Append(": ");

                            XWPFFootnote footnote = null;

                            if (r.ItemsElementName.Count > i && r.ItemsElementName[i] == RunItemsChoiceType.endnoteReference)
                            {
                                footnote = document.GetEndnoteByID(int.Parse(ftn.id));
                                if (footnote == null)
                                {
                                    footnote = document.GetFootnoteByID(int.Parse(ftn.id));
                                }
                            }
                            else
                            {
                                footnote = document.GetFootnoteByID(int.Parse(ftn.id));
                                if (footnote == null)
                                {
                                    footnote = document.GetEndnoteByID(int.Parse(ftn.id));
                                }
                            }

                            if (footnote != null)
                            {
                                bool first = true;
                                foreach (XWPFParagraph p in footnote.Paragraphs)
                                {
                                    if (!first)
                                    {
                                        footnoteText.Append("\n");
                                        first = false;
                                    }
                                    footnoteText.Append(p.Text);
                                }
                            }

                            footnoteText.Append("]");
                        }
                    }
                }
            }
        }