Class PoiUtil

java.lang.Object
com.sure.tool.poi.PoiUtil

public class PoiUtil extends Object
POI 通用门面:工作簿/行/单元格的容错访问与类型感知取值,参考 Hutool 的 PoiUtil 设计。
Since:
0.1.0
Author:
suretool
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    close(org.apache.poi.ss.usermodel.Workbook workbook)
    安静关闭工作簿。
    static org.apache.poi.ss.usermodel.Cell
    getCell(org.apache.poi.ss.usermodel.Row row, int index)
    按索引取单元格,越界或空返回 null。
    static org.apache.poi.ss.usermodel.Row
    getRow(org.apache.poi.ss.usermodel.Sheet sheet, int index)
    按索引取行,越界或空返回 null。
    static org.apache.poi.ss.usermodel.Sheet
    getSheet(org.apache.poi.ss.usermodel.Workbook workbook, int index)
    按索引取 Sheet,越界或空返回 null。
    static boolean
    isXlsx(String fileName)
    是否 xlsx 文件(按扩展名判断)。
    static Object
    readCell(org.apache.poi.ss.usermodel.Cell cell)
    类型感知读取单元格:字符串去空白、日期格式化为字符串、整数去小数点、公式取缓存值、空白返回空串。
    static void
    setCellValue(org.apache.poi.ss.usermodel.Cell cell, Object value)
    写入单元格值(String/Number/Boolean/Date 类型自动映射)。

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 - Sheet
      index - 行索引
      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 - Row
      index - 列索引
      Returns:
      Cell 或 null
    • readCell

      public static Object readCell(org.apache.poi.ss.usermodel.Cell cell)
      类型感知读取单元格:字符串去空白、日期格式化为字符串、整数去小数点、公式取缓存值、空白返回空串。
      Parameters:
      cell - 单元格
      Returns:
      值(null/字符串/数字/布尔)
    • isXlsx

      public static boolean isXlsx(String fileName)
      是否 xlsx 文件(按扩展名判断)。
      Parameters:
      fileName - 文件名
      Returns:
      是否 xlsx
    • setCellValue

      public static void setCellValue(org.apache.poi.ss.usermodel.Cell cell, Object value)
      写入单元格值(String/Number/Boolean/Date 类型自动映射)。
      Parameters:
      cell - 单元格
      value - 值