You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by sa...@apache.org on 2022/12/27 07:49:35 UTC
svn commit: r1906225 - in /poi/trunk/poi-ooxml/src: main/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java test/java/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java
Author: sayi
Date: Tue Dec 27 07:49:35 2022
New Revision: 1906225
URL: http://svn.apache.org/viewvc?rev=1906225&view=rev
Log:
Fix when bodyElements contain sdt, the inserted element is in the wrong position
Modified:
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java
poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java
Modified: poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java?rev=1906225&r1=1906224&r2=1906225&view=diff
==============================================================================
--- poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java (original)
+++ poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java Tue Dec 27 07:49:35 2022
@@ -842,7 +842,7 @@ public class XWPFDocument extends POIXML
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++;
}
}
Modified: poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java?rev=1906225&r1=1906224&r2=1906225&view=diff
==============================================================================
--- poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java (original)
+++ poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java Tue Dec 27 07:49:35 2022
@@ -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(
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org