I try to get the width of each cell and then calculate their greatest common divisor to get the colspan of each cell, but how do I get the cell Rowspan? I tried using the method TableRow.getRowHeight(), but no matter what the table looks like, it's always going to be 0. I am trying to use this method to convert to HTML, if you have a better way to convert complex tables to HTML, please help me, thanks!
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;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.