无效的标头签名;Excel 文档上的 Apache POI 的 IOException [英] Invalid header signature; IOException with Apache POI on excel document

查看:58
本文介绍了无效的标头签名;Excel 文档上的 Apache POI 的 IOException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到:

java.io.IOException: 头签名无效;读0x000201060000FFFE,预期为 0xE11AB1A1E011CFD0

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

尝试使用 apache POI HPSF 将一些自定义属性添加到 Excel 文档时.

when trying to add some custom properties to an Excel document using apache POI HPSF.

我完全确定该文件是 Excel OLE2(不是 HTML、XML 或 Excel 不会抱怨的其他内容).

I'm completely sure the file is Excel OLE2 (not HTML, XML or something else that Excel doesn't complain about).

这是我代码的相关部分:

This is a relevant part of my code:

try {
     final POIFSFileSystem poifs = new POIFSFileSystem(event.getStream());
     final DirectoryEntry dir = poifs.getRoot();
     final DocumentEntry dsiEntry = (DocumentEntry)
             dir.getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME);

     final DocumentInputStream dis = new DocumentInputStream(dsiEntry);
     final PropertySet props = new PropertySet(dis);
     dis.close();
     dsi = new DocumentSummaryInformation(props);
    }
    catch (Exception ex) {
        throw new RuntimeException
            ("Cannot create POI SummaryInformation for event: " + event +
              ", path:" + event.getPath() + 
              ", name:" + event.getPath() +
              ", cause:" + ex);
    }

在尝试使用 word 和 power point 文件(还有 OLE2)时,我遇到了同样的错误.

I get the same error when trying with word and power point files (also OLE2).

我完全没有想法,因此非常感谢任何帮助/指示:)

I'm completely out of ideas so any help/pointers are greatly appreciated :)

推荐答案

如果你翻转签名数字,你会看到文件开头的字节:

If you flip the signature number round, you'll see the bytes of the start of your file:

0x000201060000FFFE -> 0xFE 0xFF 0x00 0x00 0x06 0x01 0x02 00

0x000201060000FFFE -> 0xFE 0xFF 0x00 0x00 0x06 0x01 0x02 00

前两个字节看起来像一个 Unicode BOM,0xFEFF 表示 16 位小端.然后你有一些低控制字节,0、258 和 2 的十六进制代码,所以也许它毕竟不是一个文本文件.

The first two bytes look like a Unicode BOM, 0xFEFF means 16 bit little endian. You then have some low control bytes, the hex codes for 0 then 258 then 2, so maybe it isn't a text file after all.

那个文件真的不是 OLE2 文件,POI 给你这个错误是正确的.我不知道它是什么,但我猜它可能是 OLE2 文件的一部分,而没有它的外部 OLE2 包装器?如果你可以用office打开它,做一个另存为,POI应该可以打开它.就目前而言,该标头不是 OLE2 文件标头,因此 POI 无法为您打开它.

That file really isn't an OLE2 file, and POI is right to give you the error. I don't know what it is, but I'm guessing that perhaps it might be part of an OLE2 file without it's outer OLE2 wrapper? If you can open it with office, do a save-as and POI should be fine to open that. As it stands, that header isn't an OLE2 file header so POI can't open it for you.

这篇关于无效的标头签名;Excel 文档上的 Apache POI 的 IOException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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