POIFSFileSystem fs =new POIFSFileSystem(new FileInputStream(file));
HSSFWorkbook workBook= new HSSFWorkbook(fs);
org.apache.poi.hssf.record.RecordInputStream$LeftoverDataException: Initialisation of record 0x894 left 7 bytes remaining still to be read.
at org.apache.poi.hssf.record.RecordInputStream.hasNextRecord(RecordInputStream.java:156)
at org.apache.poi.hssf.record.RecordFactoryInputStream.nextRecord(RecordFactoryInputStream.java:231)
at org.apache.poi.hssf.record.RecordFactory.createRecords(RecordFactory.java:443)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:285)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:248)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:192)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:174)
org.apache.poi.hssf.record.RecordInputStream$LeftoverDataException: Initialisation of record 0x894 left 7 bytes remaining still to be read.
報這個錯說明通過這個Excel文件來構建它的數據單元(record)時報錯,初始化0x894(可能是序號可能是地址) record時還剩7字節未讀取,說明該excel文件該部份不合它的規範,具體錯在哪還得看了
一些老的excel版本比如2007之前可能會有問題,另外據說另存一下可能也可以解決問題
不是版本的问题,在优尔论文网上找到了答案
重写了POI 中的RecordInputSream.java , 3.7,3.8 重写后都OK
重写的方法为
Java code
public boolean hasNextRecord() throws LeftoverDataException {
if (_currentDataLength != -1 && _currentDataLength != _currentDataOffset) {
readToEndOfRecord();
}
if (_currentDataLength != DATA_LEN_NEEDS_TO_BE_READ) {
_nextSid = readNextSid();
}
return _nextSid != INVALID_SID_VALUE;
}
private void readToEndOfRecord(){
while(this._currentDataOffset<this._currentDataLength)
readByte();}}