java.lang.IllegalArgumentException:您的 InputStream 既不是 OLE2 流,也不是 OOXML 流
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16209939/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java.lang.IllegalArgumentException: Your InputStream was neither an OLE2 stream, nor an OOXML stream
提问by mee
When I'm reading Excel file(.xls format), I keep getting an Exception :
当我阅读 Excel 文件(.xls 格式)时,我不断收到异常:
java.lang.IllegalArgumentException: Your Input Stream was neither an OLE 2 stream, nor an OOXML stream.
I Go-ogled and found that if the input stream is not supporting reset or mark, I should wrap it with pushbackStream
. My input stream is not mark\reset supported.
我搜索了一下,发现如果输入流不支持重置或标记,我应该用pushbackStream
. 我的输入流不支持标记\重置。
So using pushbackStream
is the only option? How to use it? And whats the use of it?
那么使用pushbackStream
是唯一的选择吗?如何使用它?它有什么用?
Thanks
谢谢
回答by Tejus Prasad
Your InputStream was neither an OLE2 stream, nor an OOXML stream
java.lang.IllegalArgumentException: Your InputStream was neither an OLE2 stream, nor an OOXML stream
I guess you are using Workbook Factory OR a different format input file and different workbook type. This error usually pops up when its not able to not able to read the file type. Apache POI does not check the file extension. If you open it in a text editor, you'll see that instead it'll be in a different format. Or you might be initializing the workbook type to HSSF or XSSF, before using Workbook Factory.
我猜您正在使用 Workbook Factory 或不同格式的输入文件和不同的工作簿类型。当无法读取文件类型时,通常会弹出此错误。Apache POI 不检查文件扩展名。如果您在文本编辑器中打开它,您会看到它采用不同的格式。或者,您可能在使用 Workbook Factory 之前将工作簿类型初始化为 HSSF 或 XSSF。
Simpler solution is to open the file using Microsoft Excel and save it as another file(using File>SaveAs option from Microsoft Excel > Menu).
更简单的解决方案是使用 Microsoft Excel 打开文件并将其另存为另一个文件(使用Microsoft Excel > Menu 中的File>SaveAs 选项)。
Workbook Factory does not check the file extension, Instead it checks the file MIME type. Basically excel works with different files(Eg: the files created using third party applications, excel 2003 version), but Apache POI is very specific.
工作簿工厂不检查文件扩展名,而是检查文件 MIME 类型。基本上 excel 可以处理不同的文件(例如:使用第三方应用程序创建的文件,excel 2003 版本),但 Apache POI 非常具体。
PushbackInputStream
adds "push back" or "unread" functionality to another input stream. It allows you to read ahead a few bytes to see what is coming, before you can determine how to interpret the current byte.
PushbackInputStream
将“推回”或“未读”功能添加到另一个输入流。它允许您提前读取几个字节以查看即将发生的内容,然后才能确定如何解释当前字节。
If you are not using Workbook Factory, PushbackInputStream
is the only alternative I guess.
如果您不使用 Workbook Factory,PushbackInputStream
我猜这是唯一的选择。
If you can share the code here I can test it and reconfirm it.
如果您可以在此处共享代码,我可以对其进行测试并重新确认。