简体   繁体   中英

Docx4j: Get stylename of paragraph

I want to parse a docx document. I use this code to get the paragraphs and display the text:

   final String XPATH_TO_SELECT_TEXT_NODES = "//w:p";
    final List<Object> jaxbNodes = documentPart.getJAXBNodesViaXPath(XPATH_TO_SELECT_TEXT_NODES, true);

    for (Object jaxbNode : jaxbNodes){
            final String paragraphString = jaxbNode.toString();
            System.out.println("[Start]: " + paragraphString);
    }       

But i also need to know the stylename of the current paragraph. How can i do this?

Thanks for your help. 1ceman

PPr pPr = ((P) XmlUtils.unwrap(jaxbNode)).getPPr();

if (pPr != null) {
    PPrBase.PStyle pStyle = pPr.getPStyle();

    if (pStyle != null) {
        String style = pStyle.getVal();
    }
}

If there is no explicit style, then it uses the default paragraph style (as specified in the styles part).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM