Esempio n. 1
0
        /**
         * MB 24 May 2010. Created this overloaded buildHdrFtr() method because testing demonstrated
         * that the XWPFFooter or XWPFHeader object returned by calls to the CreateHeader(int, XWPFParagraph[])
         * and CreateFooter(int, XWPFParagraph[]) methods or the GetXXXXXHeader/Footer methods where
         * headers or footers had been Added to a document since it had been Created/opened, returned
         * an object that Contained no XWPFParagraph objects even if the header/footer itself did contain
         * text. The reason was that this line of code; CTHdrFtr ftr = CTHdrFtr.Factory.NewInstance();
         * Created a brand new instance of the CTHDRFtr class which was then populated with data when
         * it should have recovered the CTHdrFtr object encapsulated within the XWPFHeaderFooter object
         * that had previoulsy been instantiated in the CreateHeader(int, XWPFParagraph[]) or
         * CreateFooter(int, XWPFParagraph[]) methods.
         */
        private CT_HdrFtr buildHdrFtr(String pStyle, XWPFParagraph[] paragraphs, XWPFHeaderFooter wrapper)
        {
            CT_HdrFtr ftr = wrapper._getHdrFtr();

            if (paragraphs != null)
            {
                for (int i = 0; i < paragraphs.Length; i++)
                {
                    CT_P p = ftr.AddNewP();
                    ftr.SetPArray(i, paragraphs[i].GetCTP());
                }
            }
            else
            {
                CT_P    p    = ftr.AddNewP();
                CT_Body body = doc.Document.body;
                if (body.SizeOfPArray() > 0)
                {
                    CT_P p0 = body.GetPArray(0);
                    if (p0.IsSetRsidR())
                    {
                        byte[] rsidr        = p0.rsidR;
                        byte[] rsidrdefault = p0.rsidRDefault;
                        p.rsidP        = rsidr;
                        p.rsidRDefault = rsidrdefault;
                    }
                }
                CT_PPr pPr             = p.AddNewPPr();
                pPr.AddNewPStyle().val = (pStyle);
            }
            return(ftr);
        }