当前位置: 首页 > news >正文

cn.afterturn.easypoi.exception.excel.ExcelExportException: Excel导出错误 -> 修正过程。

先看源码。分为三个部分
实体类:

import cn.afterturn.easypoi.excel.annotation.Excel;  
import lombok.Getter;  
import lombok.Setter;  import java.io.Serializable;  
import java.math.BigDecimal;  @Getter  
@Setter  
public class ErpStoreVo implements Serializable {  @Excel(name = "店铺编号")  
private String storeNo;  @Excel(name = "店铺名称")  
private String name;  @Excel(name = "启用状态")  
private String enableStatus;
...等等其他属性
}

这是导出部分的代码:

//下载导入模板 第一个方法
@PostMapping("/importStoreModel")  
public void importStoreModel(HttpServletResponse response) throws Exception {  List<ErpStoreVo> vo = new ArrayList<>();  exportExcel(response, "店铺信息记录", ErpStoreVo.class, BaseUtil.copyList(vo,   ErpStoreVo.class));  
}
//第二个方法
import cn.afterturn.easypoi.excel.ExcelExportUtil;private void exportExcel(HttpServletResponse response, String outputName, Class<?> clazz, List<?> list) throws Exception {response.setCharacterEncoding("UTF-8");  String fileName = URLEncoder.encode(outputName, "UTF-8");  response.setHeader("Content-Disposition", "attachment; filename=" + fileName + ".xlsx");  response.setContentType("application/vnd.openxmlformats-    officedocument.spreadsheetml.sheet");  response.addHeader("Access-Control-Expose-Headers", "Content-Disposition");  response.addHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");  response.addHeader("Access-Control-Allow-Headers",  
"Content-Type,X-Requested-With,accept,Origin,Access-Control-Request-Method,Access-Control-Request-Headers,token");  Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), clazz, list);  //workbook.write(response.getOutputStream());  ServletOutputStream os = response.getOutputStream();  workbook.write(os);  os.close();
}

导出的时候会报错:

cn.afterturn.easypoi.exception.excel.ExcelExportException: Excel导出错误at cn.afterturn.easypoi.excel.export.ExcelExportService.createSheet(ExcelExportService.java:181)at cn.afterturn.easypoi.excel.ExcelExportUtil.exportExcel(ExcelExportUtil.java:116)at cn.erp.pm.PmController.exportExcel(PmController.java:198)at cn.erp.pm.PmController.importStoreModel(PmController.java:220)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:498)at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190)at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:105)at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:879)at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:793)at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040)at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909)at javax.servlet.http.HttpServlet.service(HttpServlet.java:523)at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)at javax.servlet.http.HttpServlet.service(HttpServlet.java:590)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:373)at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1594)at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException: nullat cn.afterturn.easypoi.excel.export.ExcelExportService.createSheetForMap(ExcelExportService.java:219)at cn.afterturn.easypoi.excel.export.ExcelExportService.createSheet(ExcelExportService.java:178)... 50 common frames omitted

后来修正了第一个方法,就不再报错 – 添加了实体类记录

@PostMapping("/importStoreModel")  
public void importStoreModel(HttpServletResponse response) throws Exception {  
List<ErpStoreVo> vo = new ArrayList<>();  
//没有数据时手动加一条防止报错  
vo.add(new ErpStoreVo());  
exportExcel(response, "店铺信息记录", ErpStoreVo.class, BaseUtil.copyList(vo, ErpStoreVo.class));  
}

http://www.mrgr.cn/news/64321.html

相关文章:

  • STM32 从0开始系统学习5
  • 分享一个生成二维码的js
  • linux动态库与静态库
  • 制作安装k8s需要的离线yum源
  • 3D Gaussian Splatting代码详解(一):模型训练、数据加载
  • 最新整理:Selenium自动化测试面试题
  • (九)JavaWeb后端开发——Servlet
  • 【机器学习】回归树
  • 微信小程序scroll-view吸顶css样式化表格的表头及iOS上下滑动表头的颜色覆盖、z-index应用及性能分析
  • 异步回调之Join
  • 第十七课 component组件解析
  • Rust语言有哪些常用语句?
  • zyb 的 Codeforces Round 983 (Div. 2)
  • WPF+MVVM案例实战(十八)- 自定义字体图标按钮的封装与实现(ABD类)
  • Python使用K-means实现文本聚类
  • Respiratory Physiology Neurobiology
  • TCP编程-socket(套接字)编程实战1
  • RK3568平台开发系列讲解(中断篇)延迟工作实验
  • vscode makfile编译
  • 电阻基础知识(六)-电阻的失效模式和失效机理
  • 【MacOS实操】如何基于SSH连接远程linux服务器
  • redis详细教程(7.哨兵)
  • 《GBDT 算法的原理推导》 11-13初始化模型 公式解析
  • LangChain学习之路
  • 【Comsol教程】计算流道中的流量
  • 一般无人机和FPV无人机的区别