Page 1 of 1

Styles in docx4j

PostPosted: Thu Sep 01, 2011 12:46 am
by ghossio
Hello!

I'm triying to create a docx archive and i'm looking for default styles in docx4j but i didn't find it. I would be very grateful that someone help me. I'm really trying to put bullets but all the info recived is welcome. Thank you for attention and a salute

Re: Styles in docx4j

PostPosted: Thu Sep 01, 2011 2:52 am
by jason
You'll find default styles in http://www.docx4java.org/trac/docx4j/br ... ocessingML

Have a look at how StyleDefinitionsPart.java loads them.

But for bullets, you need a NumberingDefinitionsPart (numbering.xml). See http://www.docx4java.org/trac/docx4j/br ... start.java for some hints

Re: Styles in docx4j

PostPosted: Fri Sep 02, 2011 8:33 pm
by ghossio
Thanks for the info but i dont find more default styles besides the normal and paragraph. I'm just looking like heading1 or something like that. Maybe there are more styles in this source but i didnt find. Anyway i'm grateful for the help. A salute

Re: Styles in docx4j

PostPosted: Fri Sep 02, 2011 8:52 pm
by jason
If you create a WordprocessingMLPackage using the method WordprocessingMLPackage.createPackage, it will do:

Code: Select all
      // Create a styles part
      Part stylesPart = new org.docx4j.openpackaging.parts.WordprocessingML.StyleDefinitionsPart();
      try {
         ((org.docx4j.openpackaging.parts.WordprocessingML.StyleDefinitionsPart) stylesPart)
               .unmarshalDefaultStyles();


which uses the styles defined in org/docx4j/openpackaging/parts/WordprocessingML/styles.xml. This is a relatively small set of styles, but does include Headings1-4.

There is another set of styles "org/docx4j/openpackaging/parts/WordprocessingML/KnownStyles.xml", which docx4j can use on demand via PropertyResolver.activateStyle. MainDocumentPart's createStyledParagraphOfText will use one of those styles if specified.

One enhancement which suggests itself would be to allow these 2 files to be overridden in the properties file, so you're not stuck which English language names and my choice of styles.

Re: Styles in docx4j

PostPosted: Tue Sep 06, 2011 3:01 am
by ghossio
That is. Now i got the styles (thx for the info) although dont run all the styles i 've enough.