类 ExcelTool


  • public class ExcelTool
    extends Object
    作者:
    woodwhales on 2021-01-29 15:32 excel 数据解析工具
    • 方法概要

      所有方法 静态方法 具体方法 
      修饰符和类型 方法 说明
      static org.apache.poi.ss.usermodel.Workbook buildWorkbook​(File file)
      创建 Workbook
      static org.apache.poi.ss.usermodel.Workbook buildWorkbook​(InputStream inputStream)
      创建 Workbook
      static void drawSlash​(DrawSlashContext drawSlashContext)
      绘制单元格斜线
      static void exportToOutputStream​(org.apache.poi.ss.usermodel.Workbook workbook, File file)
      导出文件
      static void exportToOutputStream​(org.apache.poi.ss.usermodel.Workbook workbook, OutputStream outputStream)
      导出至输出流
      static String formatNumeric​(Double numericCellValue)  
      static Byte getByteValue​(org.apache.poi.ss.usermodel.Row row, int cellIndex)  
      static org.apache.poi.ss.usermodel.Cell getCell​(org.apache.poi.ss.usermodel.Row row, int index)
      获取 cell 对象
      static Date getDateValue​(org.apache.poi.ss.usermodel.Row row, int cellIndex)  
      static Double getDoubleValue​(org.apache.poi.ss.usermodel.Row row, int cellIndex)  
      static String getFormatDateValue​(org.apache.poi.ss.usermodel.Row row, int cellIndex)  
      static String getFormatDateValue​(org.apache.poi.ss.usermodel.Row row, int cellIndex, String pattern)  
      static Integer getIntegerValue​(org.apache.poi.ss.usermodel.Row row, int cellIndex)  
      static Long getLongValue​(org.apache.poi.ss.usermodel.Row row, int cellIndex)  
      static String getStringValue​(org.apache.poi.ss.usermodel.Row row, int cellIndex)  
      static <T> List<T> parseData​(File file, Class<T> clazz)
      解析数据 示例:cn.woodwhales.common.example.util.excel.ExcelToolExample#testParseData2()
      static <T> List<T> parseData​(InputStream inputStream, int sheetIndex, int skipLineNumbers, java.util.function.BiFunction<ParseDataModel,​org.apache.poi.ss.usermodel.Row,​T> function)
      解析 excel 中的内容为 list 集合数据
      static <T> List<T> parseData​(InputStream inputStream, Class<T> clazz)
      解析数据 示例:cn.woodwhales.common.example.util.excel.ExcelToolExample#testParseData2()
      static <T> List<T> parseData​(InputStream inputStream, java.util.function.BiFunction<ParseDataModel,​org.apache.poi.ss.usermodel.Row,​T> function)
      解析 excel 中的内容为 list 集合数据 默认解析: 第一个 sheet 跳过第一行数据 示例参见:cn.woodwhales.common.example.util.excel.ExcelToolExample#testParseData1()
      static <T> List<T> parseData​(String filePath, int sheetIndex, int skipLineNumbers, java.util.function.BiFunction<ParseDataModel,​org.apache.poi.ss.usermodel.Row,​T> function)
      解析 excel 中的内容为 list 集合数据
      static <T> List<T> parseData​(String fileName, Class<T> clazz)
      解析数据 示例:cn.woodwhales.common.example.util.excel.ExcelToolExample#testParseData2()
      static <T> List<T> parseData​(String filePath, java.util.function.BiFunction<ParseDataModel,​org.apache.poi.ss.usermodel.Row,​T> function)
      解析 excel 中的内容为 list 集合数据 默认解析: 第一个 sheet 跳过第一行数据
    • 方法详细资料

      • parseData

        public static <T> List<T> parseData​(String filePath,
                                            java.util.function.BiFunction<ParseDataModel,​org.apache.poi.ss.usermodel.Row,​T> function)
        解析 excel 中的内容为 list 集合数据 默认解析: 第一个 sheet 跳过第一行数据
        类型参数:
        T - 返回数据泛型
        参数:
        filePath - 文件路径
        function - 解析接口
        返回:
        list
      • parseData

        public static <T> List<T> parseData​(InputStream inputStream,
                                            java.util.function.BiFunction<ParseDataModel,​org.apache.poi.ss.usermodel.Row,​T> function)
        解析 excel 中的内容为 list 集合数据 默认解析: 第一个 sheet 跳过第一行数据 示例参见:cn.woodwhales.common.example.util.excel.ExcelToolExample#testParseData1()
        类型参数:
        T - 返回数据泛型
        参数:
        inputStream - 文件输入流
        function - 解析接口
        返回:
        list
      • parseData

        public static <T> List<T> parseData​(InputStream inputStream,
                                            int sheetIndex,
                                            int skipLineNumbers,
                                            java.util.function.BiFunction<ParseDataModel,​org.apache.poi.ss.usermodel.Row,​T> function)
        解析 excel 中的内容为 list 集合数据
        类型参数:
        T - 集合数据类型
        参数:
        inputStream - 文件输入流
        sheetIndex - 读取sheet索引位置
        skipLineNumbers - 跳过第skipLineNumbers行开始读取数据
        function - 解析接口
        返回:
        成功解析的集合
      • parseData

        public static <T> List<T> parseData​(String fileName,
                                            Class<T> clazz)
        解析数据 示例:cn.woodwhales.common.example.util.excel.ExcelToolExample#testParseData2()
        类型参数:
        T - 解析数据对象类型泛型
        参数:
        fileName - 解析的文件路径
        clazz - 解析数据对象类型
        返回:
        解析数据集合
      • parseData

        public static <T> List<T> parseData​(File file,
                                            Class<T> clazz)
        解析数据 示例:cn.woodwhales.common.example.util.excel.ExcelToolExample#testParseData2()
        类型参数:
        T - 解析数据对象类型泛型
        参数:
        file - 要解析的文件对象
        clazz - 解析数据对象类型
        返回:
        解析数据集合
      • parseData

        public static <T> List<T> parseData​(InputStream inputStream,
                                            Class<T> clazz)
        解析数据 示例:cn.woodwhales.common.example.util.excel.ExcelToolExample#testParseData2()
        类型参数:
        T - 解析数据对象类型泛型
        参数:
        inputStream - 输入流
        clazz - 解析数据对象类型
        返回:
        解析数据集合
      • exportToOutputStream

        public static void exportToOutputStream​(org.apache.poi.ss.usermodel.Workbook workbook,
                                                File file)
        导出文件
        参数:
        workbook - Workbook
        file - 目标文件
      • exportToOutputStream

        public static void exportToOutputStream​(org.apache.poi.ss.usermodel.Workbook workbook,
                                                OutputStream outputStream)
        导出至输出流
        参数:
        workbook - Workbook
        outputStream - 输出流
      • parseData

        public static <T> List<T> parseData​(String filePath,
                                            int sheetIndex,
                                            int skipLineNumbers,
                                            java.util.function.BiFunction<ParseDataModel,​org.apache.poi.ss.usermodel.Row,​T> function)
        解析 excel 中的内容为 list 集合数据
        类型参数:
        T - 返回数据泛型
        参数:
        filePath - 文件路径
        sheetIndex - sheet索引
        skipLineNumbers - 跳过第几行(物理行数)
        function - 解析接口
        返回:
        list
      • getCell

        public static org.apache.poi.ss.usermodel.Cell getCell​(org.apache.poi.ss.usermodel.Row row,
                                                               int index)
        获取 cell 对象
        参数:
        row - Row 对象
        index - cell 所在索引
        返回:
        index 所在索引的 cell
      • getStringValue

        public static String getStringValue​(org.apache.poi.ss.usermodel.Row row,
                                            int cellIndex)
      • getByteValue

        public static Byte getByteValue​(org.apache.poi.ss.usermodel.Row row,
                                        int cellIndex)
      • getLongValue

        public static Long getLongValue​(org.apache.poi.ss.usermodel.Row row,
                                        int cellIndex)
      • getDoubleValue

        public static Double getDoubleValue​(org.apache.poi.ss.usermodel.Row row,
                                            int cellIndex)
      • formatNumeric

        public static String formatNumeric​(Double numericCellValue)
      • getIntegerValue

        public static Integer getIntegerValue​(org.apache.poi.ss.usermodel.Row row,
                                              int cellIndex)
      • getDateValue

        public static Date getDateValue​(org.apache.poi.ss.usermodel.Row row,
                                        int cellIndex)
      • getFormatDateValue

        public static String getFormatDateValue​(org.apache.poi.ss.usermodel.Row row,
                                                int cellIndex)
      • getFormatDateValue

        public static String getFormatDateValue​(org.apache.poi.ss.usermodel.Row row,
                                                int cellIndex,
                                                String pattern)
      • buildWorkbook

        public static org.apache.poi.ss.usermodel.Workbook buildWorkbook​(InputStream inputStream)
        创建 Workbook
        参数:
        inputStream - 输入流
        返回:
        Workbook 对象
      • buildWorkbook

        public static org.apache.poi.ss.usermodel.Workbook buildWorkbook​(File file)
        创建 Workbook
        参数:
        file - 文件
        返回:
        Workbook 对象
      • drawSlash

        public static void drawSlash​(DrawSlashContext drawSlashContext)
        绘制单元格斜线
        参数:
        drawSlashContext - drawSlashContext