POI与easyExcel

POI

Apache POI 官网

在这里插入图片描述

easyExcel

easyExcel 官网地址
EasyExcel 是阿里巴巴开源的一个excel处理框架,以使用简单、节省内存著称。
EasyExcel 能大大减少占用内存的主要原因是在解析 Excel 时没有将文件数据一次性全部加载到内存中,
而是从磁盘上一行行读取数据,逐个解析。
下图是 EasyExcel 和 POI 在解析Excel时的对比图。

在这里插入图片描述
官方文档

POI快速开始
  1. 创建项目
  2. 导入依赖

由于excel分为03和07版的所以下面两个版本都导入了,以便都练习一下,推荐使用07版本

    <dependencies>
        <!--xls(03)-->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.9</version>
        </dependency>
        <!--xlsx(07)-->
        <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.1</version>
        </dependency>
        <!--test-->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>
    </dependencies>

03 | 07 版本的写,就是对象不同,方法一样的!

需要注意:2003 版本和 2007 版本存在兼容性的问题!03最多只有 65535 行!

03版本:

	@Test
    public void testWrite03() throws Exception {
   
        System.out.println("开始");
        // 创建工作簿
        Workbook workbook = new HSSFWorkbook();
        // 创建工作表
        Sheet sheet = workbook.createSheet("人员表");
        // 创建行
        Row row = sheet.createRow(0);
        // 创建单元格
        Cell cell01 = row.createCell(0);
        cell01.setCellValue("张三");

        // 创建单元格
        Cell cell02 = row.createCell(1);
        cell02.setCellValue(new DateTime().toString("yyyy-MM-dd HH:mm:ss"));

        //创建输出流,将新建的文件输出
        FileOutputStream outputStream = new FileOutputStream(PATH+"统计表03.xls");
        // 输出
        workbook.write(outputStream);
        // 关闭流
        outputStream.close();
        System.out.println("结束");
    }

07版本

    @Test
    public void testWrite07() throws Exception{
   
        System.out.println("开始");
        Workbook workbook = new XSSFWorkbook();
        Sheet sheet = workbook.createSheet("人员表");
        Row row = sheet.createRow(0);
        Cell cell01 = row.createCell(0);
        cell01.setCellValue("skr");
        Cell cell02 = row.createCell(1);
        cell02.setCellValue(new DateTime().toString("yyyy-MM-dd HH:mm:ss"));
        FileOutputStream outputStream = new FileOutputStream(PATH+"统计表07.xlsx");
        workbook.write(outputStream);
        outputStream.close();
      
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lemon20120331

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值