[github-163] Add set level numbering on XWPFParagraph. Thanks to Mi Guoliang. This closes #163

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1871999 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2019-12-26 11:55:41 +00:00
parent 40da053a4a
commit d240fb1378
2 changed files with 29 additions and 0 deletions

View File

@ -264,6 +264,25 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
paragraph.getPPr().getNumPr().getNumId().setVal(numPos);
}
/**
* setNumILvl of Paragraph
*
* @param iLvl
* @since 4.1.2
*/
public void setNumILvl(BigInteger iLvl) {
if (paragraph.getPPr() == null) {
paragraph.addNewPPr();
}
if (paragraph.getPPr().getNumPr() == null) {
paragraph.getPPr().addNewNumPr();
}
if (paragraph.getPPr().getNumPr().getIlvl() == null) {
paragraph.getPPr().getNumPr().addNewIlvl();
}
paragraph.getPPr().getNumPr().getIlvl().setVal(iLvl);
}
/**
* Returns Ilvl of the numeric style for this paragraph.
* Returns null if this paragraph does not have numeric style.

View File

@ -299,6 +299,16 @@ public final class TestXWPFParagraph {
}
}
@Test
public void testGetSetILvl() throws IOException {
try (XWPFDocument doc = new XWPFDocument()) {
XWPFParagraph p = doc.createParagraph();
p.setNumILvl(new BigInteger("1"));
assertEquals("1", p.getNumIlvl().toString());
}
}
@Test
public void testAddingRuns() throws IOException {
try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx")) {