An error is reported when using EasyExcel to parse the table. ExcelAnalysisException: File type error, io must be available markSupported

Problem Description:

When I used EasyExcel to parse the Excel table, an error was reported. I used the method of specifying the file type to parse at the beginning. The file format is xls format. The method is to parse the original method with file enumeration type. In fact, this is also the case. No error will be reported, as follows:


Insert picture description here
Later, it is a bit awkward to see this outdated method. I plan to change it for him as shown in the figure below, click in to see a similar method, replace it with no type for analysis, and report the error as mentioned in the article. In fact, ExcelTypeEnum excelTypeEnum = ExcelTypeEnum.valueOf(in) is to recognize the file suffix of inputstream, but it still reports an error, which is a bit confusing


Insert picture description here

First check the complete error message, only post the main one

com.alibaba.excel.exception.ExcelAnalysisException: File type error,io must be available 
markSupported,you can do like this <code> new BufferedInputStream(new FileInputStream(\"/xxxx\"))</code> "






problem analysis

The main meaning is that the file type is wrong, which causes the file io to go wrong and tell us how to solve it. The general meaning is: the file type is wrong, io must be markedSupported, you can new BufferedInputStream(new FileInputStream("/xxxx"))make you wrap a layer of BufferedInputStream on the outside of the file like this , actually many Netizens also solved it like this, look at the solution


problem solved


Method 1: Just like the error message, add a BufferedInputStream to the outer layer: using the analysis of the uploaded file MultipartFile, so you can process the input stream of the file. The problem is that the file inputStream is obtained when the file is obtained, and the xls fails to be obtained. The main reason is that the poi, poi-oomxl, poi-oomxl-schemas jar packages are referenced in the project, and the version is inconsistent with the easyexcel version. It can also be resolved by updating/lowering the poi version introduced in the project to keep the versions consistent.

inputStream inputStream = file.getInputStream();//原来获取inputstream

InputStream inputStream = new BufferedInputStream(file.getInputStream());//改后正确的获取方式

InputStream inputStream = new BufferedInputStream(filePath);//直接读取本机的Excel

Method 2: Change the upload file to the xlsx format. After all, most Internet Excel uploads require templates. The templates are defined by yourself. There is no need to compete with yourself. It is generally recommended to use the xlsx format. The xls format was supported by Windows a long time ago and is not very good, so use slsx and lz to solve this problem

Guess you like

Origin blog.csdn.net/qq_42910468/article/details/103574522