alibaba/easyexcel

怎么使用HSSFWorkBook读

Open

#4,075 opened on Jan 13, 2025

View on GitHub
 (0 comments) (0 reactions) (0 assignees)Java (7,599 forks)batch import
help wanted

Repository metrics

Stars
 (33,728 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

默认读是用XSSFWorkBook吗,怎么改成HSSFWorkBook 异常:The supplied data appears to be in the OLE2 Format. You are calling the part of POI that deals with OOXML (Office Open XML) Documents.You need to call a different part of POI to process this data (eg HSSF instead of XSSF) // 写法1:JDK8+ ,不用额外写一个DemoDataListener // since: 3.0.0-beta1 String fileName = TestFileUtil.getPath() + "demo" + File.separator + "demo.xlsx"; // 这里默认每次会读取100条数据 然后返回过来 直接调用使用数据就行 // 具体需要返回多少行可以在PageReadListener的构造函数设置 EasyExcel.read(fileName, DemoData.class, new PageReadListener(dataList -> { for (DemoData demoData : dataList) { log.info("读取到一条数据{}", JSON.toJSONString(demoData)); } })).sheet().doRead();

Contributor guide