easyexcel 导出 列不全或者无内容问题排查

最近有个项目用到 easyexcel 读取excel文件,使用的版本
<easyexcel.version>2.2.11</easyexcel.version>

 	<dependency>
       <groupId>com.alibaba</groupId>
       <artifactId>easyexcel</artifactId>
       <version>${easyexcel.version}</version>
    </dependency>

写了一个demo,读取数据,发现读取了3列,部分列丢失了。
封装的excel的实体类如下

@Data
@NoArgsConstructor
@AllArgsConstructor
public class EnvironmentCityDO {

    @ExcelProperty(value = "Location_ID", index = 0)
    private String locationId;

    @ExcelProperty(value = "Location_Name_EN", index = 1)
    private String locationNameEn;

    @ExcelProperty(value = "Location_Name_ZH", index = 2)
    private String locationNameZh;

    @ExcelProperty(value = "Country_Code", index = 3)
    private String CountryCode;

    @ExcelProperty(value = "Country_Name_EN", index = 4)
    private String CountryNameEN;

    @ExcelProperty(value = "Country_Name_ZH", index = 5)
    private String Country_Name_ZH;

    @ExcelProperty(value = "Adm1_Name_EN", index = 6)
    private String Adm1_Name_EN;

    @ExcelProperty(value = "Adm1_Name_ZH", index = 7)
    private String Adm1_Name_ZH;

    @ExcelProperty(value = "Adm2_Name_EN", index = 8)
    private String Adm2_Name_EN;

    @ExcelProperty(value = "Adm2_Name_ZH", index = 9)
    private String Adm2_Name_ZH;

    @ExcelProperty(value = "Timezone", index = 10)
    private String Timezone;

    @ExcelProperty(value = "Latitude", index = 11)
    private String Latitude;

    @ExcelProperty(value = "Longitude", index = 12)
    private String Longitude;

    @ExcelProperty(value = "Adcode", index = 13)
    private String Adcode;
}
读取excel的代码如下
public static void main(String[] args) throws FileNotFoundException {


        String path = "d:/test/city.xls";

        EasyExcel.read(path, EnvironmentCityDO.class, new ReadListener<EnvironmentCityDO>() {
            private List<EnvironmentCityDO> cachedDataList = new ArrayList<>(500000);
            @Override
            public void onException(Exception exception, AnalysisContext context) throws Exception {

            }

            @Override
            public void invokeHead(Map headMap, AnalysisContext context) {
            }

            @Override
            public void invoke(EnvironmentCityDO data, AnalysisContext context) {
                log.info("___________________________________city={}", JSON.toJSONString(data));
                cachedDataList.add(data);
            }

            @Override
            public void extra(CellExtra extra, AnalysisContext context) {
            }

            @Override
            public void doAfterAllAnalysed(AnalysisContext context) {

            }

            @Override
            public boolean hasNext(AnalysisContext context) {
                return true;
            }

        }).sheet().doRead();


    }
最后发现问题出在封装的实体类上面,有数据的3列,实体类首字母是小写的,所有读取没问题,后面的实体类首字母大写的,所以读取不到。
修改实体类后,发现读取没问题了
    
@Data
@NoArgsConstructor
@AllArgsConstructor
public class EnvironmentCityDO {

    @ExcelProperty(value = "Location_ID", index = 0)
    private String locationId;

    @ExcelProperty(value = "Location_Name_EN", index = 1)
    private String locationNameEn;

    @ExcelProperty(value = "Location_Name_ZH", index = 2)
    private String locationNameZh;

    @ExcelProperty(value = "Country_Code", index = 3)
    private String countryCode;

    @ExcelProperty(value = "Country_Name_EN", index = 4)
    private String countryNameEN;

    @ExcelProperty(value = "Country_Name_ZH", index = 5)
    private String country_Name_ZH;

    @ExcelProperty(value = "Adm1_Name_EN", index = 6)
    private String adm1_Name_EN;

    @ExcelProperty(value = "Adm1_Name_ZH", index = 7)
    private String adm1_Name_ZH;

    @ExcelProperty(value = "Adm2_Name_EN", index = 8)
    private String adm2_Name_EN;

    @ExcelProperty(value = "Adm2_Name_ZH", index = 9)
    private String adm2_Name_ZH;

    @ExcelProperty(value = "Timezone", index = 10)
    private String timezone;

    @ExcelProperty(value = "Latitude", index = 11)
    private String latitude;

    @ExcelProperty(value = "Longitude", index = 12)
    private String longitude;

    @ExcelProperty(value = "Adcode", index = 13)
    private String adcode;
}

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值