aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2019-12-26 11:55:41 +0000
committerPJ Fanning <fanningpj@apache.org>2019-12-26 11:55:41 +0000
commitd240fb137878ee29e3fab4ae8b1cff0fe960c41d (patch)
tree12435ddb2732ea01a043bca76b1de34aecdc79a6
parent40da053a4a1eb8b0c40494d2e518cf5804735f42 (diff)
downloadpoi-d240fb137878ee29e3fab4ae8b1cff0fe960c41d.tar.gz
poi-d240fb137878ee29e3fab4ae8b1cff0fe960c41d.zip
[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
-rw-r--r--src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java19
-rw-r--r--src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java10
2 files changed, 29 insertions, 0 deletions
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
@@ -265,6 +265,25 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
}
/**
+ * 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
@@ -300,6 +300,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")) {