[alibaba/easyexcel]导入报错 com.alibaba.excel.exception.ExcelDataConvertException: Convert data com.alibaba.excel.metadata.data.ReadCellData@c9edc747 to class java.lang.Integer error

2024-04-30 836 views
9
异常代码
实体类:
![image](https://user-images.githubusercontent.com/96649838/221506230-ae409468-bb18-4b4c-b15c-207d0248a4a3.png)

![image](https://user-images.githubusercontent.com/96649838/221506097-4e42aaa8-62f0-4dc9-8f19-b691aa6e1114.png)

   ![image](https://user-images.githubusercontent.com/96649838/221506025-4513abae-79c2-43c5-8778-4cb910a7bbb4.png)
异常提示

com.alibaba.excel.exception.ExcelDataConvertException: Convert data com.alibaba.excel.metadata.data.ReadCellData@c9edc747 to class java.lang.Integer error at com.alibaba.excel.util.ConverterUtils.doConvertToJavaObject(ConverterUtils.java:155) at com.alibaba.excel.util.ConverterUtils.convertToJavaObject(ConverterUtils.java:100) at com.alibaba.excel.read.listener.ModelBuildEventListener.buildUserModel(ModelBuildEventListener.java:103) at com.alibaba.excel.read.listener.ModelBuildEventListener.invoke(ModelBuildEventListener.java:41) at com.alibaba.excel.read.listener.ModelBuildEventListener.invoke(ModelBuildEventListener.java:26) at com.alibaba.excel.read.processor.DefaultAnalysisEventProcessor.dealData(DefaultAnalysisEventProcessor.java:99) at com.alibaba.excel.read.processor.DefaultAnalysisEventProcessor.endRow(DefaultAnalysisEventProcessor.java:46) at com.alibaba.excel.analysis.v07.handlers.RowTagHandler.endElement(RowTagHandler.java:66) at com.alibaba.excel.analysis.v07.handlers.sax.XlsxRowHandler.endElement(XlsxRowHandler.java:91) at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source) at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source) at com.alibaba.excel.analysis.v07.XlsxSaxAnalyser.parseXmlSource(XlsxSaxAnalyser.java:203) at com.alibaba.excel.analysis.v07.XlsxSaxAnalyser.execute(XlsxSaxAnalyser.java:224) at com.alibaba.excel.analysis.ExcelAnalyserImpl.analysis(ExcelAnalyserImpl.java:124) at com.alibaba.excel.ExcelReader.read(ExcelReader.java:63) at com.alibaba.excel.ExcelReader.read(ExcelReader.java:53) at com.alibaba.excel.read.builder.ExcelReaderSheetBuilder.doRead(ExcelReaderSheetBuilder.java:65) at org.jeecg.modules.system.ciei.service.impl.ContractManagementServiceImpl.importExcel(ContractManagementServiceImpl.java:39) at org.jeecg.modules.system.ciei.service.impl.ContractManagementServiceImpl$$FastClassBySpringCGLIB$$2225de61.invoke() at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) at org.springframework.aop.framework.CglibAopProxy.invokeMethod(CglibAopProxy.java:386) at org.springframework.aop.framework.CglibAopProxy.access$000(CglibAopProxy.java:85) at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:704) at org.jeecg.modules.system.ciei.service.impl.ContractManagementServiceImpl$$EnhancerBySpringCGLIB$$7c75e7f7.importExcel() at org.jeecg.modules.system.ciei.controller.ContractManagementController.importExcel(ContractManagementController.java:160) at org.jeecg.modules.system.ciei.controller.ContractManagementController$$FastClassBySpringCGLIB$$89f915ad.invoke() at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:793) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763) at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:89) at org.jeecg.common.aspect.DictAspect.doAround(DictAspect.java:62) 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.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:634) at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:624) at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:72) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:175) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763) at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763) at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:708) at org.jeecg.modules.system.ciei.controller.ContractManagementController$$EnhancerBySpringCGLIB$$931a3e9e.importExcel() 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:205) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:150) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1071) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:964) 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:696) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) at javax.servlet.http.HttpServlet.service(HttpServlet.java:779) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) at org.springframework.web.filter.CorsFilter.doFilterInternal(CorsFilter.java:91) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:124) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) at org.springframework.boot.actuate.web.trace.servlet.HttpTraceFilter.doFilterInternal(HttpTraceFilter.java:88) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61) at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108) at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137) at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:154) at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66) at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108) at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137) at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:154) at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66) at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:458) at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:373) at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90) at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83) at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:387) at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:370) at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:154) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.doFilterInternal(WebMvcMetricsFilter.java:96) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:177) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:360) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:399) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:891) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1784) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191) at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748) Caused by: java.lang.NumberFormatException: null at java.math.BigDecimal.(BigDecimal.java:494) at java.math.BigDecimal.(BigDecimal.java:383) at java.math.BigDecimal.(BigDecimal.java:806) at com.alibaba.excel.util.NumberUtils.parseInteger(NumberUtils.java:106) at com.alibaba.excel.converters.integer.IntegerStringConverter.convertToJavaData(IntegerStringConverter.java:33) at com.alibaba.excel.converters.integer.IntegerStringConverter.convertToJavaData(IntegerStringConverter.java:18) at com.alibaba.excel.converters.Converter.convertToJavaData(Converter.java:57) at com.alibaba.excel.util.ConverterUtils.doConvertToJavaObject(ConverterUtils.java:153) ... 135 common frames omitted

问题描述

回答

5

image

6

image

8

image

1

package org.jeecg.modules.system.ciei.listener;

import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.metadata.data.ReadCellData; import com.alibaba.excel.read.listener.ReadListener; import org.jeecg.modules.system.ciei.entity.ContractManagement; import org.jeecg.modules.system.ciei.service.IContractManagementService;

import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Map;

/**

  • @author xuhuaping
  • @date 2023/2/27 */ public class ContractManagementListener implements ReadListener {

    private IContractManagementService contractManagementService;

    private List contractManagementList = new ArrayList<>(); private static final int BATCH_COUNT = 100;

    @Override public void invoke(ContractManagement contractManagement, AnalysisContext analysisContext) { System.out.println(contractManagement); contractManagementList.add(contractManagement); if (contractManagementList.size() >= BATCH_COUNT){ saveData(); contractManagementList.clear(); } }

    @Override public void doAfterAllAnalysed(AnalysisContext analysisContext) { saveData(); }

    private void saveData(){ contractManagementService.saveBatch(contractManagementList); }

    public ContractManagementListener(IContractManagementService contractManagementService) { this.contractManagementService = contractManagementService; }

    public ContractManagementListener() { }

}

0

package org.jeecg.modules.system.ciei.entity;

import java.io.Serializable; import java.io.UnsupportedEncodingException; import java.util.Date; import java.math.BigDecimal;

import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; import com.alibaba.excel.annotation.ExcelProperty; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableLogic; import lombok.AllArgsConstructor; import lombok.Data; import com.fasterxml.jackson.annotation.JsonFormat; import lombok.NoArgsConstructor; import org.springframework.format.annotation.DateTimeFormat; import org.jeecgframework.poi.excel.annotation.Excel; import org.jeecg.common.aspect.annotation.Dict; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.EqualsAndHashCode; import lombok.experimental.Accessors;

/**

  • @Description: 合同管理表
  • @Author: jeecg-boot
  • @Date: 2023-02-27
  • @Version: V1.0 */ @Data @TableName("contract_management") @Accessors(chain = true) @EqualsAndHashCode(callSuper = false) @NoArgsConstructor @AllArgsConstructor @ExcelIgnoreUnannotated @ApiModel(value="contract_management对象", description="合同管理表") public class ContractManagement implements Serializable { private static final long serialVersionUID = 1L;

    /主键*/ @TableId(type = IdType.ASSIGN_ID) @ApiModelProperty(value = "主键") private String id; /*创建人/ @ApiModelProperty(value = "创建人") private String createBy; /创建日期*/ @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") @ApiModelProperty(value = "创建日期") private Date createTime; /更新人*/ @ApiModelProperty(value = "更新人") private String updateBy; /*更新日期/ @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") @ApiModelProperty(value = "更新日期") private Date updateTime; /签订日期*/ @ExcelProperty("签单日期") @Excel(name = "签订日期", width = 20, format = "yyyy-MM-dd HH:mm:ss") @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss") @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") @ApiModelProperty(value = "签订日期") private Date dateOfSign; /合同编号*/ @Excel(name = "合同编号", width = 15) @ApiModelProperty(value = "合同编号") @ExcelProperty("合同单号") private String contractNo; /*合同名称/ @ExcelProperty("主题") @Excel(name = "合同名称", width = 15) @ApiModelProperty(value = "合同名称") private String contractTitle; /合同状态*/ @ExcelProperty("状态") @Excel(name = "合同状态", width = 15, dicCode = "contractStatus") @Dict(dicCode = "contractStatus") @ApiModelProperty(value = "合同状态") private String contractStatus; /合同分类*/ @ExcelProperty("分类") @Excel(name = "合同分类", width = 15, dicCode = "contractClassify") @Dict(dicCode = "contractClassify") @ApiModelProperty(value = "合同分类") private Integer contractClassify; /*主办部门/ @ExcelProperty("对应部门") @Excel(name = "主办部门", width = 15, dictTable = "sys_depart", dicText = "depart_name", dicCode = "id") @Dict(dictTable = "sys_depart", dicText = "depart_name", dicCode = "id") @ApiModelProperty(value = "主办部门") private String dept; /主办人*/ @ExcelProperty("创建人") @Excel(name = "主办人", width = 15, dictTable = "sys_user", dicText = "realname", dicCode = "username") @Dict(dictTable = "sys_user", dicText = "realname", dicCode = "username") @ApiModelProperty(value = "主办人") private String organiser; /客户名称*/ @ExcelProperty("对应客户") @Excel(name = "客户名称", width = 15) @ApiModelProperty(value = "客户名称") private String clientName; /*总价/ @ExcelProperty("总金额") @Excel(name = "总价", width = 15) @ApiModelProperty(value = "总价") private Double totalPrice; /预期毛利率(%)*/ @Excel(name = "预期毛利率(%)", width = 15) @ApiModelProperty(value = "预期毛利率(%)") private Double expectedGrossMargin; /*告警毛利率(%)/ @Excel(name = "告警毛利率(%)", width = 15) @ApiModelProperty(value = "告警毛利率(%)") private Double alertGrossMargin; /*情况说明/ @Excel(name = "情况说明", width = 15) @ApiModelProperty(value = "情况说明") private String remark; }

6

package org.jeecg.modules.system.ciei.service.impl;

import com.alibaba.excel.EasyExcel; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.jeecg.common.api.vo.Result; import org.jeecg.modules.system.ciei.entity.ContractManagement; import org.jeecg.modules.system.ciei.listener.ContractManagementListener; import org.jeecg.modules.system.ciei.mapper.ContractManagementMapper; import org.jeecg.modules.system.ciei.service.IContractManagementService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.servlet.ServletInputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.InputStream;

/**

  • @Description: 合同管理表
  • @Author: jeecg-boot
  • @Date: 2023-02-27
  • @Version: V1.0 */ @Service public class ContractManagementServiceImpl extends ServiceImpl<ContractManagementMapper, ContractManagement> implements IContractManagementService {

    @Override public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) throws IOException { MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; MultipartFile multipartFile = multipartRequest.getFile("file"); InputStream inputStream = multipartFile.getInputStream(); ContractManagementListener contractManagementListener = new ContractManagementListener(this); EasyExcel.read(inputStream,ContractManagement.class,contractManagementListener).sheet().doRead(); System.out.println("========================="); return null; } }

2
image

image

实体的 分类字段 excel是String 实体是Integer

2
image

lombok的注解有冲突导致cglib设置值的时候不成功