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).