poi 新增一行并拷贝上一行的样式


    /**
     * 新增一行数据并拷贝上一行的样式
     *
     * @param sheet
     * @param startRow 开始新增行数
     * @param cellNum 增加的列数
     * @return
     */
    private void insertRow(HSSFSheet sheet, int startRow, int cellNum) {
        sheet.shiftRows(startRow, sheet.getLastRowNum(), 1, true, false);
        //获取当前行
        HSSFRow rowSource = sheet.getRow(startRow - 1);
        //获取当前行样式
        HSSFCellStyle rowStyle = rowSource.getRowStyle();
        //新增行
        HSSFRow rowInsert = sheet.createRow(startRow);
        if (rowStyle != null) {
            rowInsert.setRowStyle(rowStyle);
            rowInsert.setHeight(rowSource.getHeight());
        }
        for (int col = 0; col < cellNum; col++) {
            HSSFCell cellSource = rowSource.getCell(col);
            HSSFCell cellInsert = rowInsert.createCell(col);
            HSSFCellStyle cellStyle = cellSource.getCellStyle();
            //设置单元格样式    
            if (cellStyle != null) {
                cellInsert.setCellStyle(cellStyle);
            }
        }
    }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM