正常利用EasyExcel读取excel中sheet时会调用如下接口:
public static ExcelReaderBuilder read(String pathName, ReadListener readListener) { return read((String)pathName, (Class)null, readListener); } public static ExcelReaderBuilder read(String pathName, Class head, ReadListener readListener) { ExcelReaderBuilder excelReaderBuilder = new ExcelReaderBuilder(); excelReaderBuilder.file(pathName); if (head != null) { excelReaderBuilder.head(head); } if (readListener != null) { excelReaderBuilder.registerReadListener(readListener); } return excelReaderBuilder; }
但是EasyExcel还有个读取InputStream的方法,但是这里是没有包含文件类型的信息的,先看接口源码:
public static ExcelReaderBuilder read(InputStream inputStream) { return read((InputStream)inputStream, (Class)null, (ReadListener)null); } public static ExcelReaderBuilder read(InputStream inputStream, ReadListener readListener) { return read((InputStream)inputStream, (Class)null, readListener); } public static ExcelReaderBuilder read(InputStream inputStream, Class head, ReadListener readListener) { ExcelReaderBuilder excelReaderBuilder = new ExcelReaderBuilder(); excelReaderBuilder.file(inputStream); if (head != null) { excelReaderBuilder.head(head); } if (readListener != null) { excelReaderBuilder.registerReadListener(readListener); } return excelReaderBuilder; }
因此,需要在调用时,额外指定下excel文件类型,调用参考举例:
EasyExcel.read(createInputSream(), null, listener).excelType(ExcelTypeEnum.XLSX).sheet(sheetName).doRead();
createInputSream()接口返回一个InputStream实例
标签:readListener,java,read,EasyExcel,excel,InputStream,excelReaderBuilder,null,Excel From: https://www.cnblogs.com/joeblackzqq/p/18263925