Class PoiUtil
java.lang.Object
com.sure.tool.poi.PoiUtil
POI 通用门面:工作簿/行/单元格的容错访问与类型感知取值,参考 Hutool 的
PoiUtil 设计。- Since:
- 0.1.0
- Author:
- suretool
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidclose(org.apache.poi.ss.usermodel.Workbook workbook) 安静关闭工作簿。static org.apache.poi.ss.usermodel.CellgetCell(org.apache.poi.ss.usermodel.Row row, int index) 按索引取单元格,越界或空返回null。static org.apache.poi.ss.usermodel.RowgetRow(org.apache.poi.ss.usermodel.Sheet sheet, int index) 按索引取行,越界或空返回null。static org.apache.poi.ss.usermodel.SheetgetSheet(org.apache.poi.ss.usermodel.Workbook workbook, int index) 按索引取 Sheet,越界或空返回null。static boolean是否 xlsx 文件(按扩展名判断)。static ObjectreadCell(org.apache.poi.ss.usermodel.Cell cell) 类型感知读取单元格:字符串去空白、日期格式化为字符串、整数去小数点、公式取缓存值、空白返回空串。static voidsetCellValue(org.apache.poi.ss.usermodel.Cell cell, Object value) 写入单元格值(String/Number/Boolean/Date 类型自动映射)。
-
Method Details
-
close
public static void close(org.apache.poi.ss.usermodel.Workbook workbook) 安静关闭工作簿。- Parameters:
workbook- 工作簿
-
getSheet
public static org.apache.poi.ss.usermodel.Sheet getSheet(org.apache.poi.ss.usermodel.Workbook workbook, int index) 按索引取 Sheet,越界或空返回null。- Parameters:
workbook- 工作簿index- Sheet 索引- Returns:
- Sheet 或
null
-
getRow
public static org.apache.poi.ss.usermodel.Row getRow(org.apache.poi.ss.usermodel.Sheet sheet, int index) 按索引取行,越界或空返回null。- Parameters:
sheet- Sheetindex- 行索引- Returns:
- Row 或
null
-
getCell
public static org.apache.poi.ss.usermodel.Cell getCell(org.apache.poi.ss.usermodel.Row row, int index) 按索引取单元格,越界或空返回null。- Parameters:
row- Rowindex- 列索引- Returns:
- Cell 或
null
-
readCell
类型感知读取单元格:字符串去空白、日期格式化为字符串、整数去小数点、公式取缓存值、空白返回空串。- Parameters:
cell- 单元格- Returns:
- 值(null/字符串/数字/布尔)
-
isXlsx
是否 xlsx 文件(按扩展名判断)。- Parameters:
fileName- 文件名- Returns:
- 是否 xlsx
-
setCellValue
写入单元格值(String/Number/Boolean/Date 类型自动映射)。- Parameters:
cell- 单元格value- 值
-