POI-Ecel模板导出

/**
     * 
     * @param excelPath    excel模板路径
     * @param downloadPath    文件下载路径
     * @param list    报表数据
     * @param response
     * @return
     * @throws Exception
     */
    @SuppressWarnings("resource")
    public AjaxResult excel(String excelPath, String downloadPath, List<QuestionReport> list, HttpServletResponse response) throws Exception{
        OutputStream out = null;
        //获取excel模板路径
        File fi = new File(excelPath);
        //获取文件名称
        String fileName = fi.getName(); 
        //读取excel模板  
        InputStream inp = new FileInputStream(fi);
        //创建xlsx-excel文件
        XSSFWorkbook wb = new XSSFWorkbook(inp);
        //获取第一个sheet
        XSSFSheet sheet = wb.getSheetAt(0);
        //填充数据
        for (int i = 0; i < list.size(); i++) {
            //从第三行开始创建
            XSSFRow row = sheet.createRow(2 + i);
            QuestionReport questionReport = list.get(i);
            //填充第三行第一个数据
            row.createCell(0).setCellValue(1 + i);
            row.createCell(1).setCellValue(questionReport.getProjectCode());
            row.createCell(2).setCellValue(questionReport.getProjectName());
            row.createCell(3).setCellValue(questionReport.getProjectDept());
            row.createCell(4).setCellValue(questionReport.getBuildQualityHead());
            row.createCell(5).setCellValue(questionReport.getProjectBuildingNos());
            row.createCell(6).setCellValue(questionReport.getZlQuestion());
            row.createCell(7).setCellValue(questionReport.getZlYZG());
            row.createCell(8).setCellValue(questionReport.getZlDzg());
            row.createCell(9).setCellValue(questionReport.getAqQuestion());
            row.createCell(10).setCellValue(questionReport.getAqYZG());
            row.createCell(11).setCellValue(questionReport.getAqDzg());
            row.createCell(12).setCellValue(questionReport.getCbQuestion());
            row.createCell(13).setCellValue(questionReport.getCbYZG());
            row.createCell(14).setCellValue(questionReport.getCbDzg());
            row.createCell(15).setCellValue(questionReport.getCbQuestion());
            row.createCell(16).setCellValue(questionReport.getCbYZG());
            row.createCell(17).setCellValue(questionReport.getCbDzg());
        }
        
        //修改模板内容导出新模板  
        fileName ="报事工单报表" + ".xlsx";
        out = new FileOutputStream(downloadPath + fileName);  
        wb.write(out);  
        out.close();
        out.flush();
        return AjaxResult.success(fileName);
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值