EasyExcel学习笔记

本文是关于EasyExcel的学习笔记,首先介绍了Apache poi的基本用法,包括创建不同版本的excel文件以及读取操作。接着详细讲述了EasyExcel的使用,包括在SpringBoot项目中替换poi,创建实体类,写入和读取excel文件,并提到了监听器和DAO的使用。更多内容建议参考官方文档。
摘要由CSDN通过智能技术生成

EasyExcel学习笔记

官方地址:https://www.yuque.com/easyexcel/doc/easyexcel

学习EasyExcel之前,首先要学习Apache poi

Apache poi

1、创建springboot项目,然后导入依赖.

poi是03版本,然后他的excel结尾是xls

poi-ooxml是07版本,excel结尾是xlsx

<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi</artifactId>
    <version>3.9</version>
</dependency>
&lt;!&ndash; https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml &ndash;&gt;
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml</artifactId>
    <version>3.9</version>
</dependency>
<dependency>
    <groupId>joda-time</groupId>
    <artifactId>joda-time</artifactId>
    <version>2.10.5</version>
</dependency>

2、写03版本的excel

HSSFWorkbook是创建03版本的对象。而07版本的是XSSFWorkbook

@Test
public static void ExcelWrite03()throws Exception{
   
    Workbook workbook=new HSSFWorkbook();
    Sheet sheet=workbook.createSheet("卢航统计表");
    //第一行
    Row row=sheet.createRow(0);
    Cell cell=row.createCell(0);
    cell.setCellValue("姓名");
    Cell cell1=row.createCell(1);
    cell1.setCellValue("出生日期");
    //第二行
    Row row1=sheet.createRow(1);
    Cell cell2 = row1.createCell(0);
    cell2.setCellValue("1111");

    Cell cell3 = row1.createCell(1);
    cell3.setCellValue(new DateTime().toString("yyyy-MM-dd HH-mm-ss"));
    FileOutputStream fileOutputStream=new FileOutputStream(path+"luhang03.xls");
    workbook.write(fileOutputStream);
    fileOutputStream.close();
    System.out.println("导出成功");
}

3、写07版本的excel

@Test
public static void ExcelWrite07()throws Exception{
   

    Workbook workbook=new XSSFWorkbook();
    Sheet sheet=workbook.createSheet("卢航统计表");
    //第一行
    Row row=sheet.createRow(0);
    Cell cell=row.createCell(0);
    cell.setCellValue("姓名");
    Cell cell1=row<
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值