diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 6280db36a..b81681a10 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 51111 - Correct XWPFParagraph tracking of new runs 51115 - Handle DataFormatter escaping of "." in the same way as "-" and "/" 51100 - Fix IOUtils issue for NPOIFS reading from an InputStream where every block is full 50956 - Correct XSSF cell style cloning between workbooks 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 2833695e9..a4cccccab 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java @@ -260,7 +260,9 @@ public class XWPFParagraph implements IBodyElement{ * @return a new text run */ public XWPFRun createRun() { - return new XWPFRun(paragraph.addNewR(), this); + XWPFRun run = new XWPFRun(paragraph.addNewR(), this); + runs.add(run); + return run; } /** 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 6bf3c03ff..0fa1b92ba 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java @@ -252,6 +252,16 @@ public final class TestXWPFParagraph extends TestCase { assertEquals("10", p.getNumID().toString()); } + public void testAddingRuns() throws Exception { + XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx"); + + XWPFParagraph p = doc.getParagraphs().get(0); + assertEquals(2, p.getRuns().size()); + + XWPFRun r = p.createRun(); + assertEquals(3, p.getRuns().size()); + } + public void testPictures() throws Exception { XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("VariousPictures.docx"); assertEquals(7, doc.getParagraphs().size());