0

我尝试获取每个单元格的宽度,然后计算它们的最大公约数以获得每个单元格的 colspan,但是如何获得单元格 Rowspan?我尝试使用 TableRow.getRowHeight() 方法,但无论表格是什么样子,它总是为 0。我正在尝试使用此方法转换为 HTML,如果您有更好的方法将复杂的表格转换为HTML,请帮助我,谢谢!

4

1 回答 1

0
public static Integer getRowspan(TableCell cell, int rowNum, int colNum, Table table) {
    int rowSpan = 0;
    if (cell.isVerticallyMerged()) {
        if (cell.isFirstVerticallyMerged()) {
            for (int i = rowNum + 1; i < table.numRows(); i++) {
                TableCell tableCell = table.getRow(i).getCell(colNum);
                if (tableCell.isFirstVerticallyMerged() || !tableCell.isVerticallyMerged()) {
                    rowSpan = i - rowNum;
                    break;
                } else if (i == table.numRows() - 1) {
                    rowSpan = i - rowNum + 1;
                }
            }
        }
    }
    return rowSpan;
}


public static Integer getColspan(TableCell cell, int rowNum, int colNum, Table table) {
    int colSpan = 0;
    if (cell.isMerged()) {
        if (cell.isFirstMerged()) {
            for (int i = colNum + 1; i < table.numRows(); i++) {
                TableCell tableCell = table.getRow(rowNum).getCell(i);
                if (tableCell.isFirstMerged() || !tableCell.isMerged()) {
                    colSpan = i - colNum;
                    break;
                } else if (i == table.numRows() - 1) {
                    colSpan = i - colNum + 1;
                }
            }
        }
    }
    return colSpan;
}
于 2021-11-15T08:26:49.107 回答