java 导出数据到excel


import cn.afterturn.easypoi.entity.vo.MapExcelConstants;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
import cn.afterturn.easypoi.view.PoiBaseView;

/**
     * 导出excel
     */
    @RequestMapping("/exportExcel")
    public void exportExcel(ModelMap modelMap, HttpServletRequest request,
                            HttpServletResponse response, Integer contractId) {
        List<DeviceNvrResult> deviceNvrResults = geyeDeviceNumPoolService.getNvrResults(contractId);
        List<Map> totalMaps = new ArrayList<>();

        for (DeviceNvrResult deviceNvrResult : deviceNvrResults) {
            List<DeviceCamera> deviceCameraList = deviceNvrResult.getDeviceCameraList();
            List<Map> listMaps = deviceCameraList.stream().map(v -> {
                Map map = new HashMap();
                map.put("rackNum", deviceNvrResult.getRackNum());
                map.put("projectName2", deviceNvrResult.getProjectName2());
                map.put("nvrSipAccount", deviceNvrResult.getSipAccount());
                map.put("sipPassword", deviceNvrResult.getSipPassword());
                map.put("deviceTotal", deviceCameraList.size());
                map.put("deviceSipAccount", v.getSipAccount());
                map.put("cameraName", v.getCameraName());
                map.put("nvrChannelNum", v.getNvrChannelNum());
                // nvr get sip service info
                StringBuffer stringBuffer = new StringBuffer();
                stringBuffer.append("本地SIP端口号:");
                stringBuffer.append(deviceNvrResult.getHttpPort());
                stringBuffer.append("\r\n"); // cell 字符串换行
                stringBuffer.append("SIP服务器ID:");
                stringBuffer.append(deviceNvrResult.getSipServer().getSipServerNum());
                stringBuffer.append("\r\n");
                stringBuffer.append("SIP服务器域:");
                stringBuffer.append(deviceNvrResult.getSipServer().getSipServerDomain());
                stringBuffer.append("\r\n");
                stringBuffer.append("SIP服务器地址:");
                stringBuffer.append(deviceNvrResult.getSipServer().getSipServerIp());
                stringBuffer.append("\r\n");
                stringBuffer.append("SIP服务器端口:");
                stringBuffer.append(deviceNvrResult.getSipServer().getSipServerPort());

                map.put("memo", stringBuffer.toString());
                return map;
            }).collect(Collectors.toList());
            totalMaps.addAll(listMaps);
        }

        //初始化表头
        List<ExcelExportEntity> entity = new ArrayList<>();
        entity.add(new ExcelExportEntityCustom("NVR名称", "rackNum", 10));
        entity.add(new ExcelExportEntityCustom("项目名称", "projectName2", 30));
        entity.add(new ExcelExportEntityCustom("SIP认证ID", "nvrSipAccount", 22));
        entity.add(new ExcelExportEntityCustom("密码", "sipPassword", 13));
        entity.add(new ExcelExportEntity("IP", ""));
        entity.add(new ExcelExportEntity("WG网关", ""));
        entity.add(new ExcelExportEntity("YM掩码", ""));
        entity.add(new ExcelExportEntityCustom("接入摄像头数量", "deviceTotal", 10));
        entity.add(new ExcelExportEntity("SIP通道ID摄像头", "deviceSipAccount", 22));
        entity.add(new ExcelExportEntity("摄像头名称", "cameraName", 45));
        entity.add(new ExcelExportEntity("通道号", "nvrChannelNum"));
        entity.add(new ExcelExportEntityCustom("说明", "memo", 50));

        ExportParams params = new ExportParams("工地监控摄像头信息表(电信智能眼数据导入模板)", "设备表", ExcelType.XSSF);
        short titleHeight = 15;
        params.setTitleHeight(titleHeight);
        modelMap.put(MapExcelConstants.MAP_LIST, totalMaps);
        modelMap.put(MapExcelConstants.ENTITY_LIST, entity);
        modelMap.put(MapExcelConstants.PARAMS, params);
        modelMap.put(MapExcelConstants.FILE_NAME, "工地监控摄像头信息表(电信智能眼数据导入模板)");
        PoiBaseView.render(modelMap, request, response, MapExcelConstants.EASYPOI_MAP_EXCEL_VIEW);
    }
public class ExcelExportEntityCustom extends ExcelExportEntity {
        public ExcelExportEntityCustom(String name, Object key, int width) {
            super.name = name;
            super.setWidth((double) width);
            super.setKey(key);
            super.setNeedMerge(true); // 是否合并
            super.setMergeVertical(true);// 是否垂直合并  重复数据合并
        }
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值