首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 服务器 > Apache >

Poi3.9 写下时org.apache.poi.hssf.record.RecordInputStream$LeftoverDataException

2013-03-12 
Poi3.9 写入时org.apache.poi.hssf.record.RecordInputStream$LeftoverDataException:POIFSFileSystem fs

Poi3.9 写入时org.apache.poi.hssf.record.RecordInputStream$LeftoverDataException:
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) 



解决方案:重写POIjar包中RecordInputSream.java类的hasNextRecord()方法如下


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();
}

热点排行