How to colspan a table in word with APACHE POI

前端 未结 3 749
后悔当初
后悔当初 2020-12-18 13:51

I have a code, but it\'s for rowspan a table. Can you help me to convert this to colspan code?

private static void mergeCellVertically(XWPFTable table, int c         


        
3条回答
  •  悲哀的现实
    2020-12-18 14:13

    private static void mergeCellHorizontally(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);
            }
        }
    }
    

提交回复
热议问题