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