子非鱼呀 2022-07-06 20:46 采纳率: 0%
浏览 292

EasyExcel导出时出现报错

在使用EasyExcel导出时生成Excel文件时文件创建成功,但没有任何数据,包括列名
Failed to complete request: org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.NoSuchMethodError: com.alibaba.excel.write.builder.ExcelWriterSheetBuilder.doWrite(Ljava/util/Collection;)V

@RequestMapping("print")
    public String downloadFailedUsingJson(@RequestBody List<Brancht> m1, HttpServletResponse response) throws IOException {
        // 这里注意 有同学反应使用swagger 会导致各种问题,请直接用浏览器或者用postman
        System.out.println("===========");
        System.out.println(m1);
        try {
            response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
            response.setCharacterEncoding("utf-8");
            System.out.println(4);
            // 这里需要设置不关闭流
            String fileName = "D:\\" + "入库记录" + System.currentTimeMillis() + ".xlsx";
            System.out.println(3);
            System.out.println(m1);

            EasyExcel.write(fileName, Brancht.class).autoCloseStream(Boolean.FALSE).sheet("入库记录").doWrite(m1);
//            EasyExcel.write(response.getOutputStream(), m1.get(0).getClass()).autoCloseStream(Boolean.FALSE).sheet("文物数据表")
//                    .doWrite(m1);

            System.out.println(5);
            //日志回显
            logger.info("打印成功"+fileName);
            System.out.println(6);
            return ("打印成功"+fileName);
        } catch (Exception e) {
            // 重置response
            response.reset();
            response.setContentType("application/json");
            response.setCharacterEncoding("utf-8");
            Map<String, String> map = MapUtils.newHashMap();
            map.put("status", "failure");
            map.put("message", "下载文件失败" + e.getMessage());
            response.getWriter().println(JSON.toJSONString(map));
            //日志回显
            logger.error(JSON.toJSONString(map));
            return (JSON.toJSONString(map));
        }

  • 写回答

2条回答 默认 最新

  • sum墨 2022-07-07 07:54
    关注

    你的bracht类是什么样的,要不参考下这篇文章?
    http://t.csdn.cn/ydswe

    评论

报告相同问题?

问题事件

  • 创建了问题 7月6日

悬赏问题

  • ¥20 这张图页脚大概具体代码该怎么写?
  • ¥20 WPF MVVM模式 handycontrol 框架, hc:SearchBar 控件 Text="{Binding NavMenusKeyWords}" 绑定取不到值
  • ¥15 需要手写数字信号处理Dsp三个简单题 不用太复杂
  • ¥15 数字信号处理考试111
  • ¥15 allegro17.2生成bom表是空白的
  • ¥15 请问一下怎么打通CAN通讯
  • ¥20 如何在 rocky9.4 部署 CDH6.3.2?
  • ¥35 navicat将excel中的数据导入mysql出错
  • ¥15 rt-thread线程切换的问题
  • ¥15 高通uboot 打印ubi init err 22