diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java index f4e6f9accb..55bec5ff67 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java @@ -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. diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java index 197bb231e1..f0ee0d76bb 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java @@ -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")) {