2

この関数を使用して垂直方向にマージすることができます:

private static void mergeCellsVertically(XWPFTable table, int col, int      fromRow, int toRow) {
    for (int rowIndex = fromRow; rowIndex <= toRow; rowIndex++) {
        XWPFTableCell cell = table.getRow(rowIndex).getCell(col);
        if ( rowIndex == fromRow ) {
            // The first merged cell is set with RESTART merge value
                cell.getCTTc().addNewTcPr().addNewVMerge().setVal(STMerge.RESTART);
        } else {
            // Cells which join (merge) the first one, are set with CONTINUE
            cell.getCTTc().addNewTcPr().addNewVMerge().setVal(STMerge.CONTINUE);
        }
    }
}

しかし、同様の機能で水平方向のマージを行うことはできません:

private static void mergeCellsHorizontally(XWPFTable table, int col, int fromCol, int toCol) {

    for (int colIndex = fromCol; colIndex <= toCol; colIndex++) {

        XWPFTableCell cell = table.getRow(0).getCell(colIndex);

        if ( colIndex == fromCol ) {
            // The first merged cell is set with RESTART merge value
            cell.getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.RESTART);
            cell.setText("hola");
        } else {
            // Cells which join (merge) the first one, are set with CONTINUE
            cell.getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.CONTINUE);
            cell.setText("adios");
        }
    }
}

ありがとう!

4

1 に答える 1