poi导出自动求和

          有关于动态行和动态列,长度不固定。

            // 合计行

            //列长rowLength

            //行长columnLength 

            row = sheet.createRow(rowLength);
            cell = row.createCell(0);
            cell.setCellValue("合计:");
            cell.setCellStyle(dataStyle);


            if (columnLength > 2) {
                for (int i = 2; i < columnLength; i++) {
                    cell = row.createCell(i);//设置公式前,一定要先建立表格
                    String colString = CellReference.convertNumToColString(i);  //长度转成ABC列
                    String sumstring = "SUM(" + colString + "2:" + colString + rowLength + ")";//求和公式
                    sheet.getRow(rowLength).getCell(i).setCellFormula(sumstring);
                }

            }



你可能感兴趣的:(java小白的学习历程)