When Java uses POI to read Excel files with XLS suffix, an error is reported:
Your InputStream was neither an OLE2 stream, nor an OOXML stream
Error code:
Workbook wb = WorkbookFactory.create(is);
Click the Create method to see the source code of POI:
public static Workbook create(InputStream inp) throws IOException, InvalidFormatException {
if (!((InputStream)inp).markSupported()) {
inp = new PushbackInputStream((InputStream)inp, 8);
}
if (POIFSFileSystem.hasPOIFSHeader((InputStream)inp)) {
return new HSSFWorkbook((InputStream)inp);
} else if (POIXMLDocument.hasOOXMLHeader((InputStream)inp)) {
return new XSSFWorkbook(OPCPackage.open((InputStream)inp));
} else {
throw new IllegalArgumentException("Your InputStream was neither an OLE2 stream, nor an OOXML stream");
}
}
The haspoofshade and hasooxmlreader in the two IFS are to read the first 8 bytes of the excel file stream to determine the file information. If it is not an excel type file or a binary type file, the exception “your InputStream was neither an ole2 stream, nor an OOXML stream” will be thrown directly
Analysis:
open the problematic XLS file with sublime text text editor or Notepad + +, which is XML in text form:
Open other normal XLS files with sublime text text editor as follows, which are binary:
Reason for the problem:
the XLS file in question is actually an office openxml file, also known as spreadsheetml format (XML format of Excel). Its suffix should be XML instead of XLS. It is not a standard excel file, so it will report an error when reading with POI.
Solution:
use Excel to open the problematic XLS file, as follows:
select Yes, then save the file as XLS format, and then use POI analysis to avoid reporting errors
Read More:
- [Solved] ImageIO.read(inputStream) Read .webp Format Image Error
- [Solved] Java POI Operate Excel error NullPointException
- Linux: How to Solve jdk11+easy poi Export Excel Error
- [Solved] stream Convert list to map Error: java.lang.IllegalStateException: Duplicate key
- [Solved] Minio Error: javax.xml.stream.XMLStreamException: ParseError
- I/O error while reading input message; nested exception is java.io.IOException: Stream closed
- Java will convert Excel to list set or JSON, export excel file to local, excel import and export, easyexcel tool class
- Spring cloud Netflix hystrix/acutor/hystrix.stream Error ut005023
- springboot jsp: There was an unexpected error (type=Not Found, status=404). No message available
- [Solved] POI error: Package should contain a content type part [M1.13]
- There was an unexpected error (type=Internal Server Error, status=500).Invalid bound statement (not
- [Solved] Springboot Project Start Error: An attempt was made to call the method com.google.common.collect.Multimaps.asMap
- [Solved] Eclipse Update Error: An error occurred while uninstalling session context was…
- [Solved] Error:Kotlin: Module was compiled with an incompatible version of Kotlin. The binary version of
- List: How to de-duplication according to an attribute of an object
- [Solved] Java POI export error: Invalid row number (65536) outside allowable range
- Ali easyexcel error: org.apache.poi.ss.usermodel.font.setbold (z) V
- After asynchronous file import and springboot multipartfile upload, the @async asynchronous processing reports an error: nosuchfileexception
- [Solved] Read the resources resource and convert it to file error: java.io.filenotfoundexception
- [Solved] itextpdf Read PDF File Error: Rebuild failed: trailer not found.