ziwozizhan
ziwozizhan
2018-03-13 01:50

poi 跨列合并word中的表格的单元格

5
  • 合并
  • poi
  • word

poi 合并word中的表格的单元格时,跨行可以正确合并,跨列合并则失败, 以下是合并列的代码:(poi 版本是 3.14 )

  public  void mergeCellsHorizontal(XWPFTable table, int row, int fromCell, int toCell) {  
        for (int cellIndex = fromCell; cellIndex <= toCell; cellIndex++) {  
            XWPFTableCell cell = table.getRow(row).getCell(cellIndex);  
            if ( cellIndex == fromCell ) {  
                // The first merged cell is set with RESTART merge value  
                cell.getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.RESTART);  
            } else {  
                // Cells which join (merge) the first one, are set with CONTINUE  
                cell.getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.CONTINUE);  
            }  
        }  
    }
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答

为你推荐