java 导出excel 并将图片地址转图片

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelReader;
import com.alibaba.excel.read.metadata.ReadSheet;
import com.zeus.model.*;
import com.zeus.model.common.PageResult;
import com.zeus.service.CommentsService;
import com.zeus.utils.function.EasyExcelCallable;
import com.zeus.utils.listener.CommentListener;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;


public static void main(String[] args) {
        String url = "C:\\活动\\1.xls";

        // 数据处理
        List<CommentExcel> dueList = new ArrayList<>();

        // 查询留言数据
        EasyExcelCallable<CommentExcel> callable = dataList -> {
            System.out.println("]]]");
            if(CollectionUtil.isEmpty(dataList)) {
                return;
            }
            for (CommentExcel commentExcel : dataList) {
                CommentV2Param.Comment comment = JSONUtil.toBean(commentExcel.getComment(), CommentV2Param.Comment.class);
                if(Objects.isNull(comment) || CollectionUtil.isEmpty(comment.getPicData())) {
                    continue;
                }
                //TODO 导出后将 此列内容 复制到 txt 文件中 在重新复制回来就 会以图片得形式展示
                String table = "<table><img src={src} width=200></table>";
                String img = comment.getPicData().get(0).getUrl();
                if(StringUtils.isBlank(img)) {
                    continue;
                }
                CommentExcel dueComment = new CommentExcel();
                dueComment.setPhone(commentExcel.getPhone());
                dueComment.setComment(table.replace("{src}", img));
                dueComment.setTime(commentExcel.getTime());
                dueList.add(dueComment);
            }

            System.out.println("==");

            // 写法1 JDK8+
            // since: 3.0.0-beta1
            String fileName = "C:\\活动\\2.xls";
            // 这里 需要指定写用哪个class去写,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
            // 如果这里想使用03 则 传入excelType参数即可
            EasyExcel.write(fileName, CommentExcel.class).sheet("模板").doWrite(dueList);
        };
        ExcelReader excelReader = EasyExcel.read(url, CommentExcel.class, new CommentListener(callable)).build();
        ReadSheet readSheet = EasyExcel.readSheet(0).build();
        excelReader.read(readSheet);
        // 这里千万别忘记关闭,读的时候会创建临时文件,到时磁盘会崩的
        excelReader.finish();
    }
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值