2022-07-26:easyExcel读取excel中的数据

pom.xml

<dependency> 

     <groupId>com.alibaba</groupId>                         

    <artifactId>easyexcel</artifactId>

     <version>3.0.5</version> 

</dependency>

3.0.5版本,不会因为poi的依赖报错java.lang.NoClassDefFoundError: org/apache/poi/poifs/filesystem/FileMagic

读取的xlsx样式

ExcelReadDemo类

import com.alibaba.excel.annotation.ExcelProperty;

import lombok.Data;

@Data  //提供getset方法读取到list

public class ExcelReadDemo {

    @ExcelProperty(value ="工号")

private Stringjob_number;

    @ExcelProperty(value ="姓名")

private Stringjob_name;

    @ExcelProperty(value ="总积分")

private Stringtotal_score;

    @ExcelProperty(value ="健步积分")

private Stringstep_socre;

    @ExcelProperty(value ="健身积分")

private Stringfit_socre;

    @ExcelProperty(value ="阅读积分")

private Stringread_score;

    @ExcelProperty(value ="志愿者积分")

private Stringvolunteer_score;

    @ExcelProperty(value ="工间操积分")

private Stringwork_exercise_score;

}


读取代码>>>>>>


            FileInputStream fileInputStream =null;

try {

        //获取读取的文件

        fileInputStream =new FileInputStream("C:\\Users\\1113\\Desktop\\查询信息表.xlsx");

}catch (FileNotFoundException e) {

        throw new BusinessException(BusinessStatus.FAIL,"IO读取异常");

}

                                        //读取

List list =  EasyExcel.read(fileInputStream)

                                        //设置读取的类

                                        .head(ExcelReadDemo.class)

                                        //默认读取第一个

                                        .sheet()

                                        //设置标题所在行

                                        .headRowNumber(1)

                                        //异步读取

                                        .doReadSync();

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容