0

I created a new Document file using the WordprocessingMLPackage.createPackage() method. Now I'm trying to manipulate the contents of the default style ("Heading 1", "Normal", etc.). When I'm trying to printout the values of the style's property, it returns NullPointerException. I'm pretty sure the Styles are there because the names can be printed out. but when I try to access it's paragraph properties it's null.

So now I'm wondering If I'm not accessing the contents properly.

private static void createStyleFile() throws InvalidFormatException
    {
        WordprocessingMLPackage doc = WordprocessingMLPackage.createPackage();
        List<Style> styleList = doc.getMainDocumentPart().getStyleDefinitionsPart().getJaxbElement().getStyle();

        for(int x = 0; x < styleList.size(); x++)
        {
            Style curStyle = styleList.get(x);
            //C.out(curStyle.getStyleId());
            C.out(curStyle.getName().getVal());
            curStyle.getPPr().getInd().getFirstLine().intValue();
        }
    }
kenju
  • 5,866
  • 1
  • 41
  • 41

1 Answers1

0

A style could be a paragraph, character, table or list style.

A character style won't have a PPr component, so you have to branch on style type, or test whether getPPr returns null.

If PPr is not null, getInd() could return null, so you need to check for null there as well.

I'd suggest you save your docx, unzip it, and look at styles.xml for a better idea of what is there.

JasonPlutext
  • 15,352
  • 4
  • 44
  • 84