Page 1 of 1

getPPr().getSectPr == null ?

PostPosted: Thu Oct 29, 2009 10:34 am
by dqkit
today, when I was doing with a document which contains several sections, when I tried to use getPPr().getSectPr(), it returned me null.
and body.getSectPr() is correct.
has docx4j set the section properties into PPr.sectpr yet ? if so, what is the right way to get that?
thanks.

Re: getPPr().getSectPr == null ?

PostPosted: Thu Oct 29, 2009 1:29 pm
by jason
Should work. Are you sure you were doing that on the correct P?
If you continue to have a problem, please post the XML for that p, and I'll take a look.
cheers .. Jason

Re: getPPr().getSectPr == null ?

PostPosted: Fri Oct 30, 2009 5:19 pm
by dqkit
Code: Select all
<w:body>
    <w:p w:rsidR="005A16B4" w:rsidRDefault="005A16B4">
      <w:r w:rsidR="00CB0461">
        <w:rPr>
          <w:rFonts w:hint="eastAsia"/>
        </w:rPr>
        <w:t>first</w:t>
      </w:r>
    </w:p>
    <w:p w:rsidR="00E84977" w:rsidRDefault="00E84977">
      <w:pPr>
        <w:sectPr w:rsidR="00E84977" w:rsidSect="00DF1383">
          <w:pgSz w:w="11906" w:h="16838"/>
          <w:pgMar w:top="1440" w:right="1800" w:bottom="1440" w:left="1800" w:header="851" w:footer="992" w:gutter="0"/>
          <w:cols w:space="425"/>
          <w:docGrid w:type="lines" w:linePitch="312"/>
        </w:sectPr>
      </w:pPr>
      <w:r>
        <w:rPr>
          <w:rFonts w:hint="eastAsia"/>
        </w:rPr>
        <w:t>second</w:t>
      </w:r>
    </w:p>
    <w:p w:rsidR="005A16B4" w:rsidRDefault="005A16B4">
      <w:pPr>
        <w:sectPr w:rsidR="005A16B4" w:rsidSect="005A16B4">
          <w:pgSz w:w="11906" w:h="16838"/>
          <w:pgMar w:top="720" w:right="720" w:bottom="720" w:left="720" w:header="851" w:footer="992" w:gutter="0"/>
          <w:cols w:space="425"/>
          <w:docGrid w:type="lines" w:linePitch="312"/>
        </w:sectPr>
      </w:pPr>
      <w:r>
        <w:rPr>
          <w:rFonts w:hint="eastAsia"/>
        </w:rPr>
        <w:lastRenderedPageBreak/>
        <w:t>third</w:t>
      </w:r>
      <w:r w:rsidR="000D1AB7">
        <w:rPr>
          <w:rFonts w:hint="eastAsia"/>
        </w:rPr>
        <w:t>aa</w:t>
      </w:r>
    </w:p>
    <w:p w:rsidR="0059774D" w:rsidRDefault="006B4B1D" w:rsidP="0059774D">
      <w:pPr>
        <w:pStyle w:val="2"/>
        <w:numPr>
          <w:ilvl w:val="0"/>
          <w:numId w:val="1"/>
        </w:numPr>
        <w:rPr>
          <w:rFonts w:hint="eastAsia"/>
        </w:rPr>
      </w:pPr>
      <w:r>
        <w:rPr>
          <w:rFonts w:hint="eastAsia"/>
        </w:rPr>
        <w:lastRenderedPageBreak/>
        <w:t>bb</w:t>
      </w:r>
      <w:r w:rsidR="0059774D">
        <w:rPr>
          <w:rFonts w:hint="eastAsia"/>
        </w:rPr>
        <w:t>lug</w:t>
      </w:r>
    </w:p>
    <w:p w:rsidR="0059774D" w:rsidRDefault="0059774D" w:rsidP="0059774D">
      <w:pPr>
        <w:pStyle w:val="2"/>
        <w:numPr>
          <w:ilvl w:val="0"/>
          <w:numId w:val="1"/>
        </w:numPr>
        <w:rPr>
          <w:rFonts w:hint="eastAsia"/>
        </w:rPr>
      </w:pPr>
      <w:r>
        <w:t>J</w:t>
      </w:r>
      <w:r>
        <w:rPr>
          <w:rFonts w:hint="eastAsia"/>
        </w:rPr>
        <w:t>lk</w:t>
      </w:r>
    </w:p>
    <w:p w:rsidR="0059774D" w:rsidRDefault="0059774D" w:rsidP="0059774D">
      <w:pPr>
        <w:pStyle w:val="2"/>
        <w:numPr>
          <w:ilvl w:val="0"/>
          <w:numId w:val="1"/>
        </w:numPr>
      </w:pPr>
      <w:r>
        <w:rPr>
          <w:rFonts w:hint="eastAsia"/>
        </w:rPr>
        <w:t>\hj l</w:t>
      </w:r>
    </w:p>
    <w:sectPr w:rsidR="0059774D" w:rsidSect="003D0B71">
      <w:pgSz w:w="11906" w:h="16838"/>
      <w:pgMar w:top="1440" w:right="1080" w:bottom="1440" w:left="1080" w:header="851" w:footer="992" w:gutter="0"/>
      <w:cols w:space="425"/>
      <w:docGrid w:type="lines" w:linePitch="312"/>
    </w:sectPr>
  </w:body>

I can not get the first SectPr object(the 12th line)...

Re: getPPr().getSectPr == null ?

PostPosted: Sat Oct 31, 2009 12:40 am
by jason
Either there is a problem with your code, or something strange is happening.

I can detect those sectPr with the following code:

Code: Select all
            if (((org.docx4j.wml.P)o).getPPr() != null ) {
               
               org.docx4j.wml.PPr ppr = ((org.docx4j.wml.P)o).getPPr();
               if (ppr.getSectPr()!=null) {
                  System.out.println( "paragraph contains sectpr");                  
               }               
            }


which I have added to the OpenMainDocumentAndTraverse sample. I've also now made the DocumentModel constructor register those other sections.

Re: getPPr().getSectPr == null ?

PostPosted: Sat Oct 31, 2009 6:06 am
by dqkit
Yeah, you are right.
There is something wrong with my code. :D