2010-02-01 411 views
2

我在嘗試使用POI來讀取Excel文件。它將是一個大文件(> 50k行),所以我使用eventusermodel而不是將整個文件讀入內存的簡單用戶模式。我的代碼如下所示:Java Apache POI Excel讀取異常

File file = new File("C:\\bigfile.xls"); 
    InputStream input = new FileInputStream(file); 
    EventRecordFactory factory = new EventRecordFactory(new ERFListener() { 
     @Override 
     public boolean processRecord(Record rec) 
     { 
      return true; 
     } 
    }, RecordFactory.getAllKnownRecordSIDs()); 
    factory.processRecords(input); 

,但我得到

org.apache.poi.hssf.record.RecordFormatException: The content of an excel record cannot exceed 8224 bytes 

此異常據稱是固定在3.5例外,不過,我使用的是3.6,我也從POI嘗試最新的軀幹和拉仍然是同樣的問題。

我試過收縮文件,只是有幾行,但同樣的錯誤。有沒有人處理過這個?

感謝, 傑夫

+0

你曾經得到過這個答案嗎?我有同樣的麻煩,我似乎無法在任何地方找到答案。 – Henry 2010-07-29 17:28:58

+0

我還沒有,對不起。 – 2010-08-02 12:43:48

回答

0

你有在Excel文件中的任何大的意見。如果是這樣,你可以嘗試刪除評論後。

+0

我刪除了兩行「a b c」和「d e f」但仍然出現錯誤。 – 2010-02-01 21:58:00

0

您應該使用EventRecordFactory.processRecords方法與DocumentInputStream類型作爲它的參數。 (而不是純粹的FileInputStream)。

POIFSFileSystem poifs = new POIFSFileSystem(input); 
DocumentInputStream documentInputStream = poifs.createDocumentInputStream("Workbook"); 
factory.processRecords(documentInputStream);