[GitHub-511] Prevent artificial row creation when reading XWPFTable. Thanks to Christian Appl. This closes #511

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1912149 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2023-09-06 22:32:28 +00:00
parent 9821182d57
commit 40cdc76f63
9 changed files with 15 additions and 11 deletions

View File

@ -83,7 +83,7 @@ public abstract class XWPFAbstractFootnoteEndnote implements Iterable<XWPFParag
bodyElements.add(p);
paragraphs.add(p);
} else if (o instanceof CTTbl) {
XWPFTable t = new XWPFTable((CTTbl) o, this);
XWPFTable t = new XWPFTable((CTTbl) o, this, false);
bodyElements.add(t);
tables.add(t);
} else if (o instanceof CTSdtBlock) {

View File

@ -55,7 +55,7 @@ public class XWPFComment implements IBody {
bodyElements.add(p);
paragraphs.add(p);
} else if (o instanceof CTTbl) {
XWPFTable t = new XWPFTable((CTTbl) o, this);
XWPFTable t = new XWPFTable((CTTbl) o, this, false);
bodyElements.add(t);
tables.add(t);
} else if (o instanceof CTSdtBlock) {

View File

@ -219,7 +219,7 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
bodyElements.add(p);
paragraphs.add(p);
} else if (bodyObj instanceof CTTbl) {
XWPFTable t = new XWPFTable((CTTbl) bodyObj, this);
XWPFTable t = new XWPFTable((CTTbl) bodyObj, this, false);
bodyElements.add(t);
tables.add(t);
} else if (bodyObj instanceof CTSdtBlock) {

View File

@ -57,7 +57,7 @@ public class XWPFFooter extends XWPFHeaderFooter {
bodyElements.add(p);
}
if (o instanceof CTTbl) {
XWPFTable t = new XWPFTable((CTTbl) o, this);
XWPFTable t = new XWPFTable((CTTbl) o, this, false);
tables.add(t);
bodyElements.add(t);
}
@ -105,7 +105,7 @@ public class XWPFFooter extends XWPFHeaderFooter {
bodyElements.add(p);
}
if (o instanceof CTTbl) {
XWPFTable t = new XWPFTable((CTTbl) o, this);
XWPFTable t = new XWPFTable((CTTbl) o, this, false);
tables.add(t);
bodyElements.add(t);
}

View File

@ -64,7 +64,7 @@ public class XWPFHeader extends XWPFHeaderFooter {
paragraphs.add(p);
}
if (o instanceof CTTbl) {
XWPFTable t = new XWPFTable((CTTbl) o, this);
XWPFTable t = new XWPFTable((CTTbl) o, this, false);
tables.add(t);
}
}
@ -106,7 +106,7 @@ public class XWPFHeader extends XWPFHeaderFooter {
bodyElements.add(p);
}
if (o instanceof CTTbl) {
XWPFTable t = new XWPFTable((CTTbl) o, this);
XWPFTable t = new XWPFTable((CTTbl) o, this, false);
tables.add(t);
bodyElements.add(t);
}

View File

@ -545,7 +545,7 @@ public abstract class XWPFHeaderFooter extends POIXMLDocumentPart implements IBo
bodyElements.add(p);
}
if (o instanceof CTTbl) {
XWPFTable t = new XWPFTable((CTTbl) o, this);
XWPFTable t = new XWPFTable((CTTbl) o, this, false);
tables.add(t);
bodyElements.add(t);
}

View File

@ -71,7 +71,7 @@ public class XWPFSDTContent implements ISDTContent {
bodyElements.add(p);
// paragraphs.add(p);
} else if (o instanceof CTTbl) {
XWPFTable t = new XWPFTable((CTTbl) o, part);
XWPFTable t = new XWPFTable((CTTbl) o, part,false);
bodyElements.add(t);
// tables.add(t);
} else if (o instanceof CTSdtBlock) {

View File

@ -156,11 +156,15 @@ public class XWPFTable implements IBodyElement, ISDTContents {
}
public XWPFTable(CTTbl table, IBody part) {
this(table, part, true);
}
public XWPFTable(CTTbl table, IBody part, boolean initRow) {
this.part = part;
this.ctTbl = table;
// is an empty table: I add one row and one column as default
if (table.sizeOfTrArray() == 0) {
if (initRow && table.sizeOfTrArray() == 0) {
createEmptyTable(table);
}

View File

@ -96,7 +96,7 @@ public class XWPFTableCell implements IBody, ICell {
bodyElements.add(p);
}
if (o instanceof CTTbl) {
XWPFTable t = new XWPFTable((CTTbl) o, this);
XWPFTable t = new XWPFTable((CTTbl) o, this, false);
tables.add(t);
bodyElements.add(t);
}