使用 POI 解析 Excel 但得到异常“无效的标题签名"; [英] Use POI to parse Excel but got exception "Invalid Header Signature"
问题描述
我试图使用 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: Invalid header signature; read 0x07B1FD124BEDF108, expected 0xE11AB1A1E011CFD0
我在谷歌上搜索了一些结果,基本上是说该文件实际上不是有效的 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-mode查看这个二进制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
我认为这正是 POI 所期望的(E11AB1A1E011CFD0
,但采用大端).但为什么我得到了例外?
I think it is just what POI expected (E11AB1A1E011CFD0
, but in big-endian). But why I got the exception?
顺便说一句,如果我使用带有命令 %!xxd 的 vim 来查看相同的 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
整个二进制文件似乎完全不同.我无法理解.
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 Tika 可能能够算出它是什么类型的二进制文件,所以你可以随时尝试使用 Tika-App 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屋!