Excel工具-ExcelUtil

介绍

Excel操作工具封装

使用

  1. 从文件中读取Excel为ExcelReader
  1. ExcelReader reader = ExcelUtil.getReader(FileUtil.file("test.xlsx"));
  1. 从流中读取Excel为ExcelReader(比如从ClassPath中读取Excel文件)
  1. ExcelReader reader = ExcelUtil.getReader(ResourceUtil.getStream("aaa.xlsx"));
  1. 读取指定的sheet
  1. ExcelReader reader;
  2. //通过sheet编号获取
  3. reader = ExcelUtil.getReader(FileUtil.file("test.xlsx"), 0);
  4. //通过sheet名获取
  5. reader = ExcelUtil.getReader(FileUtil.file("test.xlsx"), "sheet1");
  1. 读取大数据量的Excel
  1. private RowHandler createRowHandler() {
  2. return new RowHandler() {
  3. @Override
  4. public void handle(int sheetIndex, int rowIndex, List<Object> rowlist) {
  5. Console.log("[{}] [{}] {}", sheetIndex, rowIndex, rowlist);
  6. }
  7. };
  8. }
  9. ExcelUtil.readBySax("aaa.xlsx", 0, createRowHandler());

后续

ExcelUtil.getReader方法只是将实体Excel文件转换为ExcelReader对象进行操作。接下来请参阅章节ExcelReader对Excel工作簿进行具体操作。