使用POI解析Excel中却得到了异常"无效头标识" [英] Use POI to parse Excel but got exception "Invalid Header Signature"

查看:583
本文介绍了使用POI解析Excel中却得到了异常"无效头标识"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用Apache POI(版本3.6)来解析Excel的.xls文件,但只拿到了异常:

I was trying to use Apache POI (Version 3.6) to parse Excel .xls file, but got only Exception:

java.io.IOException异常:无效头签名;阅读0x07B1FD124BEDF108,预计0xE11AB1A1E011CFD0

java.io.IOException: Invalid header signature; read 0x07B1FD124BEDF108, expected 0xE11AB1A1E011CFD0

我用Google搜索了一些成绩,基本上说,该文件其实并不是一个有效的Excel文件(即.csv,依此类推),但后缀为.xls的结束。但我敢肯定,我的Excel文件是有效的(在Excel97-2003格式)。

I have Googled some result, which basically said that "The file is actually not a valid excel file (i.e. .csv and so on) but ended with the suffix .xls". But I'm quite sure that my excel file is valid (in Excel97-2003 format).

有关保密的考虑,我不能发布我的Excel中,但是当我使用emacs hexl模式来查看这个二进制excel文件,标题是:

For secrecy considerations, I couldn't post my excel, but when I use emacs hexl-mode to view this binary excel file, the header is:

D0CF 11E0 A1B1 1AE1

D0CF 11E0 A1B1 1AE1

我想这正是POI预期(E11AB1A1E011CFD0,但以big-endian)。但是,为什么我得到的例外呢?

I think it is just what POI expected (E11AB1A1E011CFD0, but in big-endian). But why I got the exception?

顺便说一句,如果我使用vim使用命令%XXD查看同一excel文件,我从eamcs不同的页眉:

BTW, if I use vim with command %!xxd to view the same excel file, I got a header different from eamcs:

C390 C38F 11C3 A0C2

C390 C38F 11C3 A0C2

和全二进制文件似乎是完全不同的。我无法理解。

And the whole binary file seems totally different. I cannot understand.

感谢您的帮助!

推荐答案

如果你得到的例外,那么你的文件确实不是一个真正的.xls文件。这反而或者是一些其他的文件,重命名为具有.xls扩展或损坏的文件。

If you get that exception, then your file really isn't a true .xls file. It will instead either be some other file, renamed to have a .xls extension, or a corrupted file.

我建议你尝试打开在Excel文件,并做了另存为。这可能会给你一个提示,文件类型。如果不是,做一个另存为为Excel的.xls,然后你就可以打开该文件。

I'd suggest you try opening the file in Excel, and do a Save-As. That may give you a hint as to the file type. If not, do a save-as as Excel .xls, and then you'll be able to open that file

我不知道你的文件是什么(我不认头),但我可以向你保证,它不是一个OLE2头为一个有效的.xls文件会这么做。

I don't know what you file is (I don't recognise the header), but I can assure you that it isn't an OLE2 header as a valid .xls file would have.

这可能是的Apache提卡也许能够制定出它是什么样的二进制文件,所以你可以始终与尝试蒂卡-JAR应用程序

It's possible that Apache Tika may be able to work out what kind of binary file it is, so you could always try with the Tika-App jar

这篇关于使用POI解析Excel中却得到了异常"无效头标识"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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