使用easypoi以map方式导出Excel序号自增的问题

本文介绍了一种使用Map方式导出Excel的方法,并通过一个具体案例进行了详细讲解。主要展示了如何定义导出的Excel表格结构及数据源,以及如何设置自增序号等关键配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用Map方式导出示例Demo:

    @RequestMapping(params = "exportXls")
    public String exportXls(ModelMap modelMap,HttpServletRequest request ){
       
        modelMap.put(MapExcelConstants.ENTITY_LIST, newAddExcel());
        modelMap.put(MapExcelConstants.MAP_LIST, sourceData());
        modelMap.put(MapExcelConstants.FILE_NAME, "新增数据统计");
        modelMap.put(MapExcelConstants.PARAMS, new ExportParams("新增数据统计", "导出人:" + ResourceUtil.getSessionUser().getRealName(), "导出信息"));

        return MapExcelConstants.JEECG_MAP_EXCEL_VIEW;
    }

    private List<ExcelExportEntity> newAddExcel(){
        List<ExcelExportEntity> entityList = new ArrayList<>();
        ExcelExportEntity xh = new ExcelExportEntity("序号","nu",30);
        xh.setFormat("isAddIndex");
        entityList.add(xh);
        entityList.add(new ExcelExportEntity("新增时间","clrsj",30));
        entityList.add(new ExcelExportEntity("案件名称","cajmc",50));
        entityList.add(new ExcelExportEntity("案件类型","cajlx",30));
        entityList.add(new ExcelExportEntity("案件编号","cajbh",40));
        entityList.add(new ExcelExportEntity("当事人姓名","cdsrxm",25));
        entityList.add(new ExcelExportEntity("性别","sex",15));
        entityList.add(new ExcelExportEntity("当事人身份证号","cdsrsfz",40));
        entityList.add(new ExcelExportEntity("代保管金额(元)","cdbgje",50));
        entityList.add(new ExcelExportEntity("代保管物品(件)","cdbgwp",30));
        return entityList;
    }

   private List<Map<String,String>> sourceDate(){

       Map<String,String> map = new LinkedHashMap<>();
        map.put("clrsj","2018-07-23 11:20:30");
        map.put("cajmc","李刚儿子撞人案");
        Map<String,String> map2 = new LinkedHashMap<>();
        map2.put("clrsj","2018-07-23 11:24:30");
        map2.put("cajmc","黄志慧打人案");
        List<Map<String,String>> newData = new ArrayList<>();
        newData.add(map);
        newData.add(map2);

       return newData;

   }

效果如下 :

序号是自动增加,关键是设置为:

ExcelExportEntity xh = new ExcelExportEntity("序号","nu",30);
xh.setFormat("isAddIndex");
entityList.add(xh);

 

了解更多easypoi说明文档:http://easypoi.mydoc.io/

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值