easypoi自定义模板导出

<dependency>
			<groupId>cn.afterturn</groupId>
			<artifactId>easypoi-base</artifactId>
			<version>3.2.0</version>
		</dependency>
		<dependency>
			<groupId>cn.afterturn</groupId>
			<artifactId>easypoi-web</artifactId>
			<version>3.2.0</version>
		</dependency>
		<dependency>
			<groupId>cn.afterturn</groupId>
			<artifactId>easypoi-annotation</artifactId>
			<version>3.2.0</version>
		</dependency>

由于不同版本会有不同的bug,本次操作所用版本3.2.0

  //日经营数据导出
    @PostMapping("/selectbyconditionExport")
    public void selectbyconditionExport(@RequestBody DailyRevenueDto dailyRevenueDto, HttpServletResponse response) {
   
        LocalDate today = DateTimeUtils.dateStrToLocalDate(dailyRevenueDto.getChargeTime());
        LocalDate comperdate = DateTimeUtils.dateStrToLocalDate(dailyRevenueDto.getChargeTime2());
        List<DailyRevenueVo> dailyRevenueVos =  dailyRevenueService.selectbyconditionExport(dailyRevenueDto);//查出的数据
        //模板的位置就在static文件夹下面 文件加载会报空指针这是第一个坑
        TemplateExportParams params = new TemplateExportParams(
                "日经营收入对比.xlsx");
        // 重要代码
        POICacheManager.setFileLoder(new FileLoaderImpl());
        // sheet中要填充得数据
        Map<String, Object> map = new HashMap<String, Object>();
        List<Map<String, Object>> list = BeanUtils.convertListMap(dailyRevenueVos);//list转为map
        int id=0;
        for (Map<String, Object> stringObjectMap : list) {
   
            id=id+1;
            stringObjectMap.put("id",id);

        }
        map.put("maplist", list);
        map.put("year", today.getYear());
        map.put("month", today.getMonthValue());
        map.put("day", today.getDayOfMonth());
        map.put("xingqi", DateTimeUtils.getXingqi(today));
        map.put("year1", comperdate.getYear());
        map.put("month1", comperdate.getMonthValue());
        map.put("day1", comperdate.getDayOfMonth());
        map.put("xingqi1", DateTimeUtils.getXingqi(comperdate));
        Workbook workbook = ExcelExportUtil.exportExcel(params, map);
        //根据表达式对表格设置颜色
        EasyPoiUtils.setCellColor(workbook,s -> s.contains("-"),IndexedColors.RED.getIndex(),IndexedColors.YELLOW.getIndex());
        EasyPoiUtils.downLoadExcel("日经营收入对比",response,workbook);
    }

以上代码相关的类

package com.rfca.utils;


import cn.afterturn.easypoi.cache.manager.IFileLoader;
import cn.afterturn.easypoi.util.PoiPublicUtil;
import org.apache.commons.io.FileUtils;
import org.apache.poi.util.IOUtils;
import org.slf4j.Logger;
import org.sl
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

晴天M雨天

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值