diff options
Diffstat (limited to 'poi-ooxml')
-rw-r--r-- | poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java | 2 | ||||
-rw-r--r-- | poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java | 16 |
2 files changed, 17 insertions, 1 deletions
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java index af3a4d7beb..6ab0ae9907 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java @@ -842,7 +842,7 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody { cursor.toCursor(newParaPos); while (cursor.toPrevSibling()) { o = cursor.getObject(); - if (o instanceof CTP || o instanceof CTTbl) { + if (o instanceof CTP || o instanceof CTTbl || o instanceof CTSdtBlock) { i++; } } diff --git a/poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java b/poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java index 9756291e86..fe67289913 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java @@ -465,6 +465,22 @@ public final class TestXWPFDocument { } @Test + void testInsertNewParagraphWithSdt() throws IOException { + try (XWPFDocument doc = new XWPFDocument()) { + doc.createTOC(); + doc.createParagraph(); + try (XWPFDocument docx = XWPFTestDataSamples.writeOutAndReadBack(doc)) { + XWPFParagraph paragraph = docx.getParagraphArray(0); + XmlCursor xmlCursor = paragraph.getCTP().newCursor(); + XWPFParagraph insertNewParagraph = docx.insertNewParagraph(xmlCursor); + + assertEquals(insertNewParagraph, docx.getParagraphs().get(0)); + assertEquals(insertNewParagraph, docx.getBodyElements().get(1)); + } + } + } + + @Test @Disabled("XWPF should be able to write to a new Stream when opened Read-Only") void testWriteFromReadOnlyOPC() throws Exception { try (OPCPackage opc = OPCPackage.open( |