问题描述
我在读取一个Excel的我的本地系统上的文件。我使用POI的jar 3.7版本,但得到的错误无效的头签名;
阅读-2300849302551019537或十六进制0xE011BDBFEFBDBFEF,
预计-2226271756974174256或十六进制0xE11AB1A1E011CFD0。
打开使用Excel的XLS文件工作正常。
在codeblock将它发生在哪里:
任何人的想法?
/ **
*从InputStream创建一个新的HeaderBlockReader
*
* @参数流源的InputStream
*
*上的错误或坏的数据抛出IOException异常
* /
公共HeaderBlockReader(InputStream的流)抛出IOException
//在这一点上,我们不知道有多大我们
//块大小
//因此,阅读前32个字节进行检查,然后
//读取块的其余部分
字节[] = blockStart新的字节[32];
INT bsCount = IOUtils.readFully(流blockStart);
如果(bsCount!= 32){
扔alertShortRead(bsCount,32);
} //验证签名
长签名= LittleEndian.getLong(blockStart,_signature_offset); 如果(签字!= _signature){
//它是通常的犯罪嫌疑人之一?
字节[] = OOXML_FILE_HEADER POIFSConstants.OOXML_FILE_HEADER;
如果(blockStart [0] == OOXML_FILE_HEADER [0]&放大器;&放大器;
blockStart [1] == OOXML_FILE_HEADER [1]&放大器;&放大器;
blockStart [2] == OOXML_FILE_HEADER [2]&放大器;&放大器;
blockStart [3] == OOXML_FILE_HEADER [3]){
抛出新OfficeXmlFileException(提供的数据似乎是在Office 2007+ XML,你在呼唤与OLE2 Office文档涉及POI的一部分,你需要调用POI的不同部分来处理这些数据(如XSSF代替HSSF));
}
如果((签名&安培; 0xFF8FFFFFFFFFFFFFL)== 0x0010000200040009L){
// BIFF2原料流与BOF开始(SID = 0x0009,大小= 0x0004单元,数据= 0x00t0)
抛出新抛出:IllegalArgumentException(提供的数据似乎是在BIFF2格式。
+POI只支持BIFF8格式);
} //给一般错误
抛出新IOException异常(无效的头签名;读
+ longToHex(签字)+,预计
+ longToHex(_signature));
}
只是一个爱迪,如果你使用maven确保在资源标签过滤设置为false。
否则,行家往往导致腐败XLS文件复制阶段
I am reading one excel file on my local system. I am using POI jar Version 3.7, but getting error Invalid header signature; read -2300849302551019537 or in Hex 0xE011BDBFEFBDBFEF , expected -2226271756974174256 or in Hex 0xE11AB1A1E011CFD0.
Opening the xls file with Excel works fine.
The codeblock where it happens:Anybody an idea ?
/**
* create a new HeaderBlockReader from an InputStream
*
* @param stream the source InputStream
*
* @exception IOException on errors or bad data
*/
public HeaderBlockReader(InputStream stream) throws IOException {
// At this point, we don't know how big our
// block sizes are
// So, read the first 32 bytes to check, then
// read the rest of the block
byte[] blockStart = new byte[32];
int bsCount = IOUtils.readFully(stream, blockStart);
if(bsCount != 32) {
throw alertShortRead(bsCount, 32);
}
// verify signature
long signature = LittleEndian.getLong(blockStart, _signature_offset);
if (signature != _signature) {
// Is it one of the usual suspects?
byte[] OOXML_FILE_HEADER = POIFSConstants.OOXML_FILE_HEADER;
if(blockStart[0] == OOXML_FILE_HEADER[0] &&
blockStart[1] == OOXML_FILE_HEADER[1] &&
blockStart[2] == OOXML_FILE_HEADER[2] &&
blockStart[3] == OOXML_FILE_HEADER[3]) {
throw new OfficeXmlFileException("The supplied data appears to be in the Office 2007+ XML. You are calling the part of POI that deals with OLE2 Office Documents. You need to call a different part of POI to process this data (eg XSSF instead of HSSF)");
}
if ((signature & 0xFF8FFFFFFFFFFFFFL) == 0x0010000200040009L) {
// BIFF2 raw stream starts with BOF (sid=0x0009, size=0x0004, data=0x00t0)
throw new IllegalArgumentException("The supplied data appears to be in BIFF2 format. "
+ "POI only supports BIFF8 format");
}
// Give a generic error
throw new IOException("Invalid header signature; read "
+ longToHex(signature) + ", expected "
+ longToHex(_signature));
}
Just an idee, if you using maven make sure in the resource tag filtering is set to false.Otherwise maven tends to corrupt xls files in the copying phase
这篇关于无效的标题读xls文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!