poi xwpf 操作word表格,怎么合并单元格?
展开全部
for (int j = 0; j < tr.numCells(); j++) {
cell = tr.getCell(j);//取得单元格
if(j < tr.numCells()-1){//获取下一个单元格,用于判断是否合并
nextCell = tr.getCell(j+1);
}else{
nextCell = null;
}
int[] leftEdges = getLeftEdges(table,tr);
if(tempIndex< leftEdges.length-1 && cell.getLeftEdge() != leftEdges[tempIndex+1] ){
htmlTextTbl.append(" colspan='");
//如果不相等,继续循环,直到找着相等的为止
int colspan = 1;
for(int edgeIndex = tempIndex+1; edgeIndex < leftEdges.length; edgeIndex++){
System.out.println(leftEdges[edgeIndex] == nextCell.getLeftEdge());
if(leftEdges[edgeIndex] != nextCell.getLeftEdge() ){
colspan ++;
}else{
break;
}
}
tempIndex += colspan;
htmlTextTbl.append(colspan+"'");
}
}
cell = tr.getCell(j);//取得单元格
if(j < tr.numCells()-1){//获取下一个单元格,用于判断是否合并
nextCell = tr.getCell(j+1);
}else{
nextCell = null;
}
int[] leftEdges = getLeftEdges(table,tr);
if(tempIndex< leftEdges.length-1 && cell.getLeftEdge() != leftEdges[tempIndex+1] ){
htmlTextTbl.append(" colspan='");
//如果不相等,继续循环,直到找着相等的为止
int colspan = 1;
for(int edgeIndex = tempIndex+1; edgeIndex < leftEdges.length; edgeIndex++){
System.out.println(leftEdges[edgeIndex] == nextCell.getLeftEdge());
if(leftEdges[edgeIndex] != nextCell.getLeftEdge() ){
colspan ++;
}else{
break;
}
}
tempIndex += colspan;
htmlTextTbl.append(colspan+"'");
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询