报错一:使用EasyExcel解析表格时报错ExcelAnalysisException: File type error,io must be available markSupported
https://blog.csdn.net/qq_42910468/article/details/103574522
InputStream inputStream = new BufferedInputStream(new FileInputStream(fileUrl));
开发
<!-- 阿里开源EXCEL --> <dependency> <groupId>com.alibaba</groupId> <artifactId>easyexcel</artifactId> <version>2.1.6</version> </dependency>
package com.power.manager; import com.alibaba.excel.EasyExcel; import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.event.AnalysisEventListener; import com.power.manager.dto.WeekPowerLineLossExcelDto; import org.junit.Test; import java.io.BufferedInputStream; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; import java.util.ArrayList; import java.util.List; public class EasyExcelTest { @Test public void importExcel() throws FileNotFoundException { String url = "E:\test\test\202002\2002xiansun.xls"; InputStream is = new BufferedInputStream(new FileInputStream(url)); final int CAPACITY = 5000; List<WeekPowerLineLossExcelDto> list = new ArrayList<>(CAPACITY); System.out.println("开始"); EasyExcel.read(is, WeekPowerLineLossExcelDto.class, new AnalysisEventListener<WeekPowerLineLossExcelDto>() { @Override public void invoke(WeekPowerLineLossExcelDto dto, AnalysisContext analysisContext) { list.add(dto); if(list.size() >= CAPACITY){ System.out.println(list.size()); list.clear(); } } @Override public void doAfterAllAnalysed(AnalysisContext analysisContext) { System.out.println("最终剩余:" + list.size()); list.clear();//解析结束销毁不用的资源 } }).sheet().doRead(); System.out.println("结束"); } }
package com.power.manager.dto; import com.alibaba.excel.annotation.ExcelProperty; import lombok.Data; /** * 参考:https://juejin.im/post/5dae4fdd51882554c07585d1 * 导入 */ @Data public class WeekPowerLineLossExcelDto { //序号 @ExcelProperty(index = 0) private Integer num; @ExcelProperty(index = 1) private String countDate; @ExcelProperty(index = 2) private String powerSupplyCompanyName; }
运行结果:
开始
5000
5000
5000
最终剩余:1308
结束