mirror of
https://github.com/apache/poi.git
synced 2026-02-27 20:40:08 +08:00
Fix when bodyElements contain sdt, the inserted element is in the wrong position
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1906225 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a84c9e0be6
commit
98d51e4139
@ -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++;
|
||||
}
|
||||
}
|
||||
|
||||
@ -464,6 +464,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 {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user