类 ExcelTool
- java.lang.Object
-
- cn.woodwhales.common.util.excel.ExcelTool
-
public class ExcelTool extends Object
- 作者:
- woodwhales on 2021-01-29 15:32 excel 数据解析工具
-
-
方法概要
所有方法 静态方法 具体方法 修饰符和类型 方法 说明 static org.apache.poi.ss.usermodel.WorkbookbuildWorkbook(File file)创建 Workbookstatic org.apache.poi.ss.usermodel.WorkbookbuildWorkbook(InputStream inputStream)创建 Workbookstatic voiddrawSlash(DrawSlashContext drawSlashContext)绘制单元格斜线static voidexportToOutputStream(org.apache.poi.ss.usermodel.Workbook workbook, File file)导出文件static voidexportToOutputStream(org.apache.poi.ss.usermodel.Workbook workbook, OutputStream outputStream)导出至输出流static StringformatNumeric(Double numericCellValue)static BytegetByteValue(org.apache.poi.ss.usermodel.Row row, int cellIndex)static org.apache.poi.ss.usermodel.CellgetCell(org.apache.poi.ss.usermodel.Row row, int index)获取 cell 对象static DategetDateValue(org.apache.poi.ss.usermodel.Row row, int cellIndex)static DoublegetDoubleValue(org.apache.poi.ss.usermodel.Row row, int cellIndex)static StringgetFormatDateValue(org.apache.poi.ss.usermodel.Row row, int cellIndex)static StringgetFormatDateValue(org.apache.poi.ss.usermodel.Row row, int cellIndex, String pattern)static IntegergetIntegerValue(org.apache.poi.ss.usermodel.Row row, int cellIndex)static LonggetLongValue(org.apache.poi.ss.usermodel.Row row, int cellIndex)static StringgetStringValue(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- Workbookfile- 目标文件
-
exportToOutputStream
public static void exportToOutputStream(org.apache.poi.ss.usermodel.Workbook workbook, OutputStream outputStream)导出至输出流- 参数:
workbook- WorkbookoutputStream- 输出流
-
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)
-
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
-
-