POI 插入行

来源:互联网 发布:怎样获得淘宝优惠券 编辑:程序博客网 时间:2024/05/15 05:36
    private static void insertRow(Sheet sheet, int starRow, int rows)
    {  
            sheet.shiftRows(starRow + 1, sheet.getLastRowNum(), rows, true, false);  
                starRow = starRow - 1;
            for (int i = 0; i < rows; i++) {  
                    Row sourceRow = null;
                Row targetRow = null;  
                Cell sourceCell = null;  
                Cell targetCell = null;  
            short m;

            starRow = starRow + 1;
            sourceRow = sheet.getRow(starRow);
            targetRow = sheet.createRow(starRow + 1);
            targetRow.setHeight(sourceRow.getHeight());

            for (m = sourceRow.getFirstCellNum(); m < sourceRow.getLastCellNum(); m++)
            {
             System.out.println( "m:------>" + m);
                sourceCell = sourceRow.getCell(m);
                targetCell = targetRow.createCell(m);

                targetCell.setCellStyle(sourceCell.getCellStyle());
                 targetCell.setCellType(sourceCell.getCellType());
              }
 
            }
    }
0 0