[英]How do I maintain cell widths when merging cells in a word table using apache poi?
[英]How do I get table information in word2003 using POI?
我尝试获取每个单元格的宽度,然后计算它们的最大公约数以获取每个单元格的 colspan,但是如何获取单元格 Rowspan? 我尝试使用 TableRow.getRowHeight() 方法,但无论表格看起来如何,它始终为 0。我正在尝试使用此方法转换为 HTML,如果您有更好的方法将复杂表格转换为HTML,请帮助我,谢谢!
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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.