I have a code, but it\'s for rowspan a table. Can you help me to convert this to colspan code?
private static void mergeCellVertically(XWPFTable table, int c
Axel Richter answer is very complete. But there is a problem if you don't work CTTcPr and other XML keys, and mix with POI API's.
You have to use
// Cells which join (merge) the first one, must be removed
int sizeOfTc = currentRow.getCtRow().sizeOfTcArray();
for(int colIndex = toCol; colIndex > fromCol; colIndex--) {
if (colIndex < sizeOfTc) currentRow.getCtRow().removeTc(colIndex);
currentRow.removeCell(colIndex);
}
because there is a bug on Apache POI. The removeCell() method doesn't remove the Tc from the row. And if you use removeTc(), it doesn't remove the cell from the internal POI's list. You have to use both.