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));  
}
相关推荐
疯一样的码农37 分钟前
Java初学者指南
java·开发语言
LUwantAC1 小时前
Java学习路线:JUL日志系统(一)日志框架介绍
java·开发语言·学习
佚先森2 小时前
IAPP仿源码大师主界面UI
java
 嘘 3 小时前
文件操作:Xml转Excel
xml·python·excel
q567315233 小时前
使用 Python 编辑 XML 文件中的文本字段
xml·java·数据库·python·sqlite
LeMay083 小时前
基础算法——排序算法(冒泡排序,选择排序,堆排序,插入排序,希尔排序,归并排序,快速排序,计数排序,桶排序,基数排序,Java排序)
java·算法·排序算法
大山很山3 小时前
Python简介和程序设计思想 |【python技能树知识点1~2】
java·网络·python
果粒陈爱写代码3 小时前
SpringBoot day 1105
java·spring boot·后端
colman wang3 小时前
Java入门二刷
java·开发语言