poi导出(生成)excel基础代码

    public XSSFWorkbook generateWarterAlarmMsgExcel(List<WarterAlarmVO> warterAlarmVOS, String date, String timeType) throws ParseException {

        if(warterAlarmVOS != null && warterAlarmVOS.size() != 0){
            // 创建一个webbook,对应一个Excel文件---反馈导入情况
            XSSFWorkbook backBook = new XSSFWorkbook();
            // 设置各列宽度
            Sheet bSheet = backBook.createSheet("故障登记表");
            bSheet.setColumnWidth(0, 120 * 20);
            bSheet.setColumnWidth(1, 120 * 100);
            bSheet.setColumnWidth(2, 120 * 30);
            bSheet.setColumnWidth(3, 120 * 60);
            bSheet.setColumnWidth(4, 120 * 50);
            bSheet.setColumnWidth(5, 120 * 40);
            bSheet.setColumnWidth(6, 120 * 40);
            bSheet.setColumnWidth(7, 120 * 40);
            bSheet.setColumnWidth(8, 120 * 70);

            // 居中加粗样式
            CellStyle cellStyle = backBook.createCellStyle();
            cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
            cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);

            // 字体加粗
            Font font = backBook.createFont();
            font.setBoldweight((short) 80);
            cellStyle.setFont(font);

            //字体大小
            Font fontSize = backBook.createFont();
            fontSize.setFontHeightInPoints((short) 12);//设置excel数据字体大小

            // 居中不加粗样式
            CellStyle cellStyleCenter = backBook.createCellStyle();
            cellStyleCenter.setAlignment(HSSFCellStyle.ALIGN_CENTER);
            cellStyleCenter.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);

            // 在sheet中添加表头第1行---行
            Row bRow = bSheet.createRow(0);
            // 表格
            Cell bCell = null;
            // 表头第一行内容
            bCell = bRow.createCell(0);
            bCell.setCellValue("序号");
            bCell.setCellStyle(cellStyle);
            bCell = bRow.createCell(1);
            bCell.setCellValue("联网单位名称");
            bCell.setCellStyle(cellStyle);
            bCell = bRow.createCell(2);
            bCell.setCellValue("水警信息数量");
            bCell.setCellStyle(cellStyle);
            bCell = bRow.createCell(3);
            bCell.setCellValue("报警点位");
            bCell.setCellStyle(cellStyle);
            bCell = bRow.createCell(4);
            bCell.setCellValue("是否电话通知");
            bCell.setCellStyle(cellStyle);
            bCell = bRow.createCell(5);
            bCell.setCellValue("联网单位消防负责人");
            bCell.setCellStyle(cellStyle);
            bCell = bRow.createCell(6);
            bCell.setCellValue("负责人电话");
            bCell.setCellStyle(cellStyle);
            bCell = bRow.createCell(7);
            bCell.setCellValue("备注");
            bCell.setCellStyle(cellStyle);
            bCell = bRow.createCell(8);
            bCell.setCellValue("日期");
            bCell.setCellStyle(cellStyle);
            bRow.setHeight((short) 1000);

            String dateRange = generateExcelDate(date,timeType);
            // 遍历---向数据库中添加数据
            //数据从第二行开始写入
            int rowFlag = 1;
            int num = 1;
            for (WarterAlarmVO warterAlarmVO : warterAlarmVOS) {

                bRow = bSheet.createRow(rowFlag);
                bRow.createCell(0).setCellValue(num);
                bRow.createCell(1).setCellValue(warterAlarmVO.getCompanyName());
                bRow.createCell(2).setCellValue(warterAlarmVO.getWarterAlarmCount());
                bRow.createCell(3).setCellValue(warterAlarmVO.getAlarmPointPosition());
                bRow.createCell(4).setCellValue("是");
                bRow.createCell(5).setCellValue(warterAlarmVO.getFiresafetyDutyPersonName());
                bRow.createCell(6).setCellValue(warterAlarmVO.getFiresafetyDutyPhoneNumber());
                bRow.createCell(7).setCellValue(warterAlarmVO.getRemark());
                bRow.createCell(8).setCellValue(dateRange);
                bRow.setRowStyle(cellStyle);
                num++;
                rowFlag++;
            }
            //合并表头
            bSheet.addMergedRegion(new CellRangeAddress(1, rowFlag-1, 8, 8));

            return backBook;
        }
        else {
            return getAlarmFail("未查询到数据!","报警数统计报表");
        }
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值