Fix addition and removal of columns in XSLTTable

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1870523 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Alain Béarez 2019-11-28 00:51:43 +00:00
parent 557b67cb24
commit da5d7d44d5
2 changed files with 10 additions and 0 deletions

View File

@ -179,6 +179,9 @@ public class XSLFTable extends XSLFGraphicFrame implements Iterable<XSLFTableRow
long width = _table.getTblGrid().getGridColArray(_table.getTblGrid().sizeOfGridColArray() - 1).getW();
CTTableCol col = _table.getTblGrid().addNewGridCol();
col.setW(width);
for(CTTableRow row : _table.getTrList()) {
row.addNewTc();
}
updateRowColIndexes();
}
@ -194,6 +197,9 @@ public class XSLFTable extends XSLFGraphicFrame implements Iterable<XSLFTableRow
long width = _table.getTblGrid().getGridColArray(colIdx).getW();
CTTableCol col = _table.getTblGrid().insertNewGridCol(colIdx);
col.setW(width);
for(CTTableRow row : _table.getTrList()) {
row.insertNewTc(colIdx);
}
updateRowColIndexes();
}
@ -204,6 +210,9 @@ public class XSLFTable extends XSLFGraphicFrame implements Iterable<XSLFTableRow
*/
public void removeColumn(int colIdx) {
_table.getTblGrid().removeGridCol(colIdx);
for(CTTableRow row : _table.getTrList()) {
row.removeTc(colIdx);
}
updateRowColIndexes();
}

View File

@ -71,6 +71,7 @@ public class TestXSLFTable {
tab.insertColumn(0);
assertEquals(tab.getColumnWidth(1), tab.getColumnWidth(0), 0.00001);
tab.addColumn();
tab.getCell(0, data[0].length + 1);
assertEquals(tab.getColumnWidth(tab.getNumberOfColumns() - 2), tab.getColumnWidth(tab.getNumberOfColumns() - 1), 0.00001);
tab.removeColumn(0);
tab.removeColumn(tab.getNumberOfColumns() - 1);