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();
+ for(XSLFTableRow row : _rows) {
+ XSLFTableCell cell = row.addCell();
+ cell.getTextBody(true);
}
updateRowColIndexes();
}
long width = _table.getTblGrid().getGridColArray(colIdx).getW();
CTTableCol col = _table.getTblGrid().insertNewGridCol(colIdx);
col.setW(width);
- for(CTTableRow row : _table.getTrList()) {
- row.insertNewTc(colIdx);
+ for(XSLFTableRow row : _rows) {
+ XSLFTableCell cell = row.insertCell(colIdx);
+ cell.getTextBody(true);
}
updateRowColIndexes();
}
*/
public void removeColumn(int colIdx) {
_table.getTblGrid().removeGridCol(colIdx);
- for(CTTableRow row : _table.getTrList()) {
- row.removeTc(colIdx);
+ for(XSLFTableRow row : _rows) {
+ row.removeCell(colIdx);
}
updateRowColIndexes();
}
return _row;
}
+ @Override
public Iterator<XSLFTableCell> iterator(){
return _cells.iterator();
}
_cells.add(cell);
if(_table.getNumberOfColumns() < _row.sizeOfTcArray()) {
- _table.getCTTable().getTblGrid().addNewGridCol().setW(Units.toEMU(100.0));
+ _table.getCTTable().getTblGrid().addNewGridCol().setW(Units.toEMU(100.0));
}
_table.updateRowColIndexes();
return cell;
}
-
+
+ /**
+ * Insert a new cell at the given index.
+ * @param colIdx the column index.
+ * @since POI 4.1.2
+ */
+ public XSLFTableCell insertCell(int colIdx){
+ CTTableCell c = _row.insertNewTc(colIdx);
+ c.set(XSLFTableCell.prototype());
+ XSLFTableCell cell = new XSLFTableCell(c, _table);
+ _cells.add(colIdx, cell);
+
+ if(_table.getNumberOfColumns() < _row.sizeOfTcArray()) {
+ _table.getCTTable().getTblGrid().insertNewGridCol(colIdx).setW(Units.toEMU(100.0));
+ }
+ _table.updateRowColIndexes();
+ return cell;
+ }
+
+ /**
+ * Remove the cell at the given index.
+ * @param colIdx the column index.
+ * @since POI 4.1.2
+ */
+ public void removeCell(int colIdx){
+ _row.removeTc(colIdx);
+ _cells.remove(colIdx);
+ _table.updateRowColIndexes();
+ }
+
/**
* Merge cells of a table row, inclusive.
* Indices are 0-based.
tab.insertColumn(0);
assertEquals(tab.getColumnWidth(1), tab.getColumnWidth(0), 0.00001);
+ assertNotNull(tab.getCell(0, 0).getTextBody());
tab.addColumn();
tab.getCell(0, data[0].length + 1);
assertEquals(tab.getColumnWidth(tab.getNumberOfColumns() - 2), tab.getColumnWidth(tab.getNumberOfColumns() - 1), 0.00001);
+ assertNotNull(tab.getCell(0, tab.getNumberOfColumns() - 1).getTextBody());
tab.removeColumn(0);
tab.removeColumn(tab.getNumberOfColumns() - 1);
assertEquals(data[0].length, tab.getNumberOfColumns());