EasyPOI简单导入Excel示例

1、添加依赖

<dependency>
    <groupId>cn.afterturn</groupId>
    <artifactId>easypoi-base</artifactId>
    <version>4.1.0</version>
</dependency>
<dependency>
    <groupId>cn.afterturn</groupId>
    <artifactId>easypoi-web</artifactId>
    <version>4.1.0</version>
</dependency>
<dependency>
    <groupId>cn.afterturn</groupId>
    <artifactId>easypoi-annotation</artifactId>
    <version>4.1.0</version>
</dependency>

2、实体创建

@Data
public class ReportModel implements Serializable {

    @Excel(name = "报案号",orderNum = "0")
    private String reportNo;

    @Excel(name = "单号",orderNum = "1")
    private String bizOrderNo;
}

3、Excel示例

EasyPOI简单导入Excel示例

 

 4、示例代码

    @Test
    public void testFileParse() throws Exception {

        ImportParams params = new ImportParams();
        params.setTitleRows(0);//示例Excel中没有标题 故此设置titlsRows为0
        params.setHeadRows(1); //示例Excel中表头在第一行 所以设置headRows为1
        FileInputStream inputStream = new FileInputStream(new File("test.xlsx"));
        List<ReportModel> list = ExcelImportUtil.importExcel(inputStream, ReportModel.class, params);
        System.out.println(list.size());
    }

  

上一篇:Typora基本使用方法


下一篇:Spring Boot整合EasyPoi