hutool-poi Excel文件(xls, xlsx)不支持csv
Hutool-poi是针对Apache POI的封装,因此需要用户自行引入POI库,Hutool默认不引入。到目前为止,Hutool-poi支持:
Excel文件(xls, xlsx)的读取(ExcelReader)
Excel文件(xls,xlsx)的写出(ExcelWriter)
具体代码
// pom
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>4.0.12</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.17</version>
</dependency>
public void hutoolRead() {
try {
excelPath = "C:\\Users\\admin\\Desktop\\开发任务分配.xlsx";
File excel = FileUtil.file(excelPath);
if (excel.isFile() && excel.exists()) { //判断文件是否存在
ExcelReader reader = ExcelUtil.getReader(excel);
//开始解析
List<Map<String, Object>> list = reader.readAll();
System.out.println(JSONObject.toJSON(list));
} else {
System.out.println("找不到指定的文件");
}
} catch (Exception e) {
e.printStackTrace();
}
}
具体参考api.