Skip to content

Commit

Permalink
[GitHub-511] Prevent artificial row creation when reading XWPFTable. …
Browse files Browse the repository at this point in the history
…Thanks to Christian Appl. This closes #511

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1912149 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
pjfanning committed Sep 6, 2023
1 parent 9821182 commit 40cdc76
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ protected void init() {
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected void init() {
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ protected void onDocumentRead() throws IOException {
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public XWPFFooter(XWPFDocument doc, CTHdrFtr hdrFtr) throws IOException {
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);
}
Expand Down Expand Up @@ -105,7 +105,7 @@ protected void onDocumentRead() throws IOException {
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public XWPFHeader(XWPFDocument doc, CTHdrFtr hdrFtr) {
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);
}
}
Expand Down Expand Up @@ -106,7 +106,7 @@ protected void onDocumentRead() throws IOException {
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ public void readHdrFtr() {
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public XWPFSDTContent(CTSdtContentBlock block, IBody part, IRunBody parent) {
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,15 @@ public XWPFTable(CTTbl table, IBody part, int row, int col) {
}

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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public XWPFTableCell(CTTc cell, XWPFTableRow tableRow, IBody part) {
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);
}
Expand Down

0 comments on commit 40cdc76

Please sign in to comment.