java.lang.IllegalArgumentException:您的 InputStream 既不是 OLE2 流,也不是 OOXML 流 [英] java.lang.IllegalArgumentException: Your InputStream was neither an OLE2 stream, nor an OOXML stream

查看:71
本文介绍了java.lang.IllegalArgumentException:您的 InputStream 既不是 OLE2 流,也不是 OOXML 流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我读取 Excel 文件(.xls 格式)时,我不断收到异常:

When I'm reading Excel file(.xls format), I keep getting an Exception :

java.lang.IllegalArgumentException: Your Input Stream was neither an OLE 2 stream, nor an OOXML stream.

我搜索了一下,发现如果输入流不支持重置或标记,我应该用 pushbackStream 包装它.我的输入流不支持标记\重置.

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?

谢谢

推荐答案

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

我猜您正在使用 Workbook Factory 或不同格式的输入文件和不同的工作簿类型.当无法读取文件类型时,通常会弹出此错误.Apache POI 不检查文件扩展名.如果您在文本编辑器中打开它,您会看到它采用不同的格式.或者,您可能在使用 Workbook Factory 之前将工作簿类型初始化为 HSSF 或 XSSF.

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.

更简单的解决方案是使用 Microsoft Excel 打开文件并将其另存为另一个文件(使用 Microsoft Excel > Menu 中的 File>Save As 选项).

Simpler solution is to open the file using Microsoft Excel and save it as another file(using File>Save As option from Microsoft Excel > Menu).

Workbook Factory 不检查文件扩展名,而是检查文件 MIME 类型.基本上 excel 可以处理不同的文件(例如:使用第三方应用程序创建的文件,excel 2003 版本),但 Apache POI 非常具体.

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.

PushbackInputStream 向另一个输入流添加推回"或未读"功能.它允许您提前读取几个字节以查看即将发生的内容,然后才能确定如何解释当前字节.

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.

如果您不使用 Workbook Factory,我猜PushbackInputStream 是唯一的选择.

If you are not using Workbook Factory, PushbackInputStream is the only alternative I guess.

如果你能在这里分享代码,我可以测试并再次确认.

If you can share the code here I can test it and reconfirm it.

这篇关于java.lang.IllegalArgumentException:您的 InputStream 既不是 OLE2 流,也不是 OOXML 流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆