iexcel-excel 读取和写入,解决 excel OOM 问题

打印 上一主题 下一主题

主题 847|帖子 847|积分 2541

项目简介

IExcel 用于优雅地读取和写入 excel。
避免大 excel 出现 oom,简约而不简单。
特性


  • 一行代码搞定一切
  • OO 的方式操作 excel,编程更加方便优雅。
  • sax 模式读取,SXSS 模式写入。避免 excel 大文件 OOM。
  • 基于注解,编程更加灵活。
  • 设计简单,注释完整。方便大家学习改造。
  • 可根据注解指定表头顺序
  • 支持 excel 文件内容 bytes[] 内容获取,便于用户自定义操作。
变更日志

变更日志
v0.0.9 主要变更

Fixed @ExcelField注解失效问题
创作缘由

实际工作和学习中,apache poi 操作 excel 过于复杂。
近期也看了一些其他的工具框架:

  • easypoi
  • easyexcel
  • hutool-poi
都或多或少难以满足自己的实际需要,于是就自己写了一个操作 excel 导出的工具。
实现:在阿里 easyexcel 的基础上进行封装,提升使用的简易度。
快速开始

环境要求

jdk1.8+
maven 3.x
引入 jar

使用 maven 管理。
  1. <dependency>
  2.      <groupId>com.github.houbb</groupId>
  3.      <artifactId>iexcel</artifactId>
  4.      <version>1.0.0</version>
  5. </dependency>
复制代码
Excel 写入

示例
  1. // 基本属性
  2. final String filePath = PathUtil.getAppTestResourcesPath()+"/excelHelper.xls";
  3. List<User> models = User.buildUserList();
  4. // 直接写入到文件
  5. ExcelHelper.write(filePath, models);
复制代码
其中:

  • User.java
  1. public class User {
  2.     private String name;
  3.     private int age;
  4.     //fluent getter/setter/toString()
  5. }
复制代码

  • buildUserList()
构建对象列表方法如下:
  1. /**
  2. * 构建用户类表
  3. * @return 用户列表
  4. * @since 0.0.4
  5. */
  6. public static List<User> buildUserList() {
  7.     List<User> users = new ArrayList<>();
  8.     users.add(new User().name("hello").age(20));
  9.     users.add(new User().name("excel").age(19));
  10.     return users;
  11. }
复制代码
写入效果

excel 内容生成为:
  1. name        age
  2. hello        20
  3. excel        19
复制代码
Excel 读取

示例
  1. final String filePath = PathUtil.getAppTestResourcesPath()+"/excelHelper.xls";
  2. List<User> userList = ExcelHelper.read(filePath, User.class);
复制代码
信息
  1. [User{name='hello', age=20}, User{name='excel', age=19}]
复制代码
SAX 读
  1. // 待生成的 excel 文件路径
  2. final String filePath = PathUtil.getAppTestResourcesPath()+"/excelReadBySax.xls";
  3.         AbstractSaxReadHandler<User> saxReadHandler = new AbstractSaxReadHandler<User>() {
  4.             @Override
  5.             protected void doHandle(int i, List<Object> list, User user) {
  6.                 System.out.println(user);
  7.             }
  8.         };
  9. ExcelHelper.readBySax(User.class, saxReadHandler, filePath);
复制代码
文档

01-ExcelBs 引导类使用说明
02-ExcelField 注解指定字段属性
03-ExcelField#order 指定列顺序
04-ExcelBs#bytes 获取文件字节信息
Bug & Issues

欢迎提出宝贵意见:Bug & Issues
本文由博客一文多发平台 OpenWrite 发布!

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

梦见你的名字

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表