Page 1 of 1

Geting document style issue..

PostPosted: Wed Jul 15, 2009 5:41 am
by dqkit
hi~
I have the problem to get the style.
look, I have a content:
1. 一级标题............................1
1.1. 二级标题........................1
1.1.1. 三级标题...............1
1.2. 二级标题........................2
2. 一级标题............................2
3. 一级标题............................3
4. 一级标题............................4
5. 一级标题............................5
and what exactly I wan to do is check the first line space of each P.
I know there is a pStyle in the pPr.
Code: Select all
<w:p w:rsidR="00706525" w:rsidRDefault="00706525">
               <w:pPr>
                  <w:pStyle w:val="20" />
                  <w:tabs>
                     <w:tab w:val="left" w:pos="1050" />
                     <w:tab w:val="right" w:leader="dot"
                        w:pos="8296" />
                  </w:tabs>
                  <w:rPr>
                     <w:noProof />
                  </w:rPr>
               </w:pPr>
               <w:hyperlink w:anchor="_Toc235354801"
                  w:history="1">
                  <w:r w:rsidRPr="004D3C0A">
                     <w:rPr>
                        <w:rStyle w:val="a5" />
                        <w:noProof />
                     </w:rPr>


should I go to the "word/stylex.xml" ??
Or should I find that in
Code: Select all
    <w:pPr>
      <w:tabs>
        <w:tab w:val="center" w:pos="4153"/>
        <w:tab w:val="right" w:pos="8306"/>
      </w:tabs>
      <w:snapToGrid w:val="0"/>
      <w:jc w:val="left"/>
    </w:pPr>

? the tab
I still can read the content of stylex.xml. thanks so much for your attention.

Re: Geting document style issue..

PostPosted: Wed Jul 15, 2009 10:59 pm
by jason
I'm not quite sure what you mean by "first line space". If you mean the space after the number, that's defined in the numbering definition. See the package org.docx4j.model.listnumbering.

In general, to get the effective value of a property, you have to follow the inheritance hierarchy. See org.docx4j.model.PropertyResolver which does this work for you.

I hope these pointers help; please post again if you are still stuck!

cheers

Jason

Re: Geting document style issue..

PostPosted: Thu Jul 16, 2009 3:41 am
by dqkit
the content should be like this:
1. 一级标题............................1
(space here )1.1. 二级标题....................1
(space here space here )1.1.1. 三级标题............1
(space here )1.2. 二级标题....................2
2. 一级标题............................2
3. 一级标题............................3
4. 一级标题............................4
5. 一级标题............................5

I want to know the space before the chapter number and after the page number.
thanks.
---Kit Liao

Re: Geting document style issue..

PostPosted: Thu Jul 16, 2009 8:09 pm
by jason
The quick n dirty way is to directly apply formatting to the paragraph, using the w:ind element like so:

Code: Select all
                  <w:p>
                        <w:pPr>
                            <w:pStyle w:val="ListParagraph"/>
                            <w:numPr>
                                <w:ilvl w:val="0"/>
                                <w:numId w:val="1"/>
                            </w:numPr>
                            <w:ind w:left="3549" w:hanging="357"/>
                        </w:pPr>
                        <w:r>
                            <w:t>Now I will indent…</w:t>
                        </w:r>
                    </w:p>


The proper way to do it, is to make the setting in the numbering part ("/word/numbering.xml"), again by setting w:pPr/w:ind. You have to set it on the relevant numId ilvl . You should have a look at the WordprocessingML spec to read how it works.

I suggest you set things how you want them in the Word interface, save the result as .xml, and open it in a text editor to look at it.

To have your numbering part set correctly, you can:

1. programmatically change an existing part using docx4j
2. start with a document you created in Word which has the correct numbering settings (and modify that programmatically), or
3. use docx4j to inject into your word document a numbering.xml file containing what you want.