Class ExcelUtil
java.lang.Object
com.sure.tool.poi.ExcelUtil
Excel 读写工具类(xlsx/xls),参考 Hutool 的
ExcelUtil 设计。
读取时单元格类型感知(数字/日期/布尔/字符串),写入时按 Java 类型自动落格; Bean 写入以字段名作为表头。
- Since:
- 0.1.0
- Author:
- suretool
-
Method Summary
Modifier and TypeMethodDescription读取 Excel 第一个工作表(每行为单元格值列表)。读取指定工作表。从指定行(含)开始读取工作表。readSheetNames(File file) 工作表名称列表。readWithHeader(File file) 读取第一个工作表,第一行作为表头,返回 Map 列表。readWithHeader(File file, int sheetIndex) 读取指定工作表,第一行作为表头,返回 Map 列表。static File写入行数据到指定工作表。static File写入行数据到默认工作表。static FilewriteBeans(File file, String sheetName, List<?> beans) Bean 列表写入 Excel(字段名作为表头)。static FilewriteBeans(File file, String sheetName, List<?> beans, String... headers) 写入 Bean 列表,可指定表头(表头同时作为字段选择器)。static FilewriteBeans(File file, List<?> beans) Bean 列表写入 Excel(字段名作为表头)。
-
Method Details
-
read
读取 Excel 第一个工作表(每行为单元格值列表)。- Parameters:
file- Excel 文件- Returns:
- 行列表
- Throws:
IOException- 读取失败
-
read
读取指定工作表。- Parameters:
file- Excel 文件sheetIndex- 工作表索引- Returns:
- 行列表
- Throws:
IOException- 读取失败
-
readWithHeader
读取第一个工作表,第一行作为表头,返回 Map 列表。- Parameters:
file- Excel 文件- Returns:
- Map 列表
- Throws:
IOException- 读取失败
-
readWithHeader
读取指定工作表,第一行作为表头,返回 Map 列表。- Parameters:
file- Excel 文件sheetIndex- 工作表索引- Returns:
- Map 列表
- Throws:
IOException- 读取失败
-
readSheetNames
工作表名称列表。- Parameters:
file- Excel 文件- Returns:
- 名称列表
- Throws:
IOException- 读取失败
-
write
写入行数据到默认工作表。- Parameters:
file- 目标文件rows- 行列表(每行为值列表)- Returns:
- 目标文件
- Throws:
IOException- 写入失败
-
write
写入行数据到指定工作表。- Parameters:
file- 目标文件sheetName- 工作表名rows- 行列表(每行为值列表)- Returns:
- 目标文件
- Throws:
IOException- 写入失败
-
writeBeans
Bean 列表写入 Excel(字段名作为表头)。- Parameters:
file- 目标文件beans- Bean 列表- Returns:
- 目标文件
- Throws:
IOException- 写入失败
-
writeBeans
Bean 列表写入 Excel(字段名作为表头)。- Parameters:
file- 目标文件sheetName- 工作表名beans- Bean 列表- Returns:
- 目标文件
- Throws:
IOException- 写入失败
-
read
从指定行(含)开始读取工作表。- Parameters:
file- Excel 文件sheetIndex- 工作表索引startRow- 起始行号(0 起)- Returns:
- 行数据列表
- Throws:
IOException- IO 异常
-
writeBeans
public static File writeBeans(File file, String sheetName, List<?> beans, String... headers) throws IOException 写入 Bean 列表,可指定表头(表头同时作为字段选择器)。- Parameters:
file- Excel 文件sheetName- 工作表名beans- Bean 列表headers- 表头字段名(按需选择列)- Returns:
- 文件
- Throws:
IOException- IO 异常
-