Skip to content

Commit

Permalink
[github-151] XWPFRun: allow style retrieval. This closes #151
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1860464 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
pjfanning committed Jun 1, 2019
1 parent 8638dbf commit 5e33bd4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java
Expand Up @@ -1213,6 +1213,25 @@ public void setStyle(String styleId) {
style.setVal(styleId);
}

/**
* Return this run's style ID. If this run has no style (no run properties or properties without a style),
* an empty string is returned.
*
* @since 4.1.1
*/
public String getStyle() {
CTRPr pr = getCTR().getRPr();
if (pr == null) {
return "";
}

CTString style = pr.getRStyle();
if (style == null) {
return "";
}

return style.getVal();
}


/**
Expand Down
Expand Up @@ -783,6 +783,8 @@ public void testSetStyleId() throws IOException {
assertNotNull("Expected to find a run style ID", candStyleId);
assertEquals(styleId, candStyleId);

assertEquals(styleId, run.getStyle());

document.close();
}

Expand Down

0 comments on commit 5e33bd4

Please sign in to comment.