easypoi操作excel表格数据导入

1.maven坐标

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

2.代码

    /**
     * excel批量导入
     * @param file
     * @return
     */
    @PostMapping("/excel")
    public String importExcel(@RequestParam("file") MultipartFile file) throws Exception
    {
        ImportParams importParams = new ImportParams();
        importParams.setTitleRows(1);
        importParams.setHeadRows(1);

        ExcelImportResult<Student> result = ExcelImportUtil.importExcelMore(file.getInputStream(), Student.class, importParams);
        List<Student> studentExportList = result.getList();
        studentExportList.forEach(student -> System.err.println(student));
        
        //下面进行数据库保存数据,处理自己公司相应业务
        return "ok";
    }


@Data
public class Student
{
    @Excel(name = "姓名", orderNum = "1", width = 18)
    private String name;
    @Excel(name = "年龄", orderNum = "2", width = 18)
    private int age;
    @Excel(name = "性别", orderNum = "3", width = 18)
    private String sex;
}

3.准备表格数据

在这里插入图片描述

4.调用接口结果

在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值