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

先看源码。分为三个部分

实体类:

java 复制代码
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;
...等等其他属性
}

这是导出部分的代码:

java 复制代码
//下载导入模板 第一个方法
@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();
}

导出的时候会报错:

java 复制代码
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: null
	at 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

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

java 复制代码
@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));  
}
相关推荐
因我你好久不见1 分钟前
springboot java ffmpeg 视频压缩、提取视频帧图片、获取视频分辨率
java·spring boot·ffmpeg
程序员shen1616113 分钟前
抖音短视频saas矩阵源码系统开发所需掌握的技术
java·前端·数据库·python·算法
Ling_suu31 分钟前
SpringBoot3——Web开发
java·服务器·前端
天使day1 小时前
SpringMVC
java·spring·java-ee
CodeClimb1 小时前
【华为OD-E卷-简单的自动曝光 100分(python、java、c++、js、c)】
java·python·华为od
风清云淡_A1 小时前
【java基础系列】实现数字的首位交换算法
java·算法
Gao_xu_sheng1 小时前
Java程序打包成exe,无Java环境也能运行
java·开发语言
大卫小东(Sheldon)1 小时前
Java的HTTP接口测试框架Gatling
java
谢家小布柔1 小时前
java中的继承
java·开发语言