无效的头签名; IOException异常与Apache POI对Excel文档 [英] Invalid header signature; IOException with Apache POI on excel document

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

问题描述

我收到:

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).

这是我的code的相关部分:

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和电源点文件(也OLE2)努力时,我得到了同样的错误。

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

我完全没了主意,所以任何帮助/指针是极大的AP preciated:)

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的0×00 0×00 0×06 0×01 0×02 00

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

前两个字节看起来像一个统一code BOM,是指为0xFEFF 16位的小端。那么你有一些低控制字节,十六进制codeS为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.

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

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