Java Apache POI Excel读取exception
我正在尝试使用POI来读取一个Excel文件。 这将是一个大文件(> 50k行),所以我使用eventusermodel而不是简单的用户模式,它将整个文件读入内存。 我的代码如下所示:
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
这个exception应该是固定在3.5,但是,我使用3.6,我也尝试从POI最新的干线拉,仍然是同样的问题。
我已经尝试收缩文件,只是有几行,但相同的错误。 有没有人处理过这个?
谢谢,杰夫
你有没有在Excel文件中的任何大的意见。 如果是这样,你可以尝试删除评论后。
您应该使用DocumentInputStreamtypes的EventRecordFactory .processRecords方法作为参数。 (而不是纯FileInputStream
)。
POIFSFileSystem poifs = new POIFSFileSystem(input); DocumentInputStream documentInputStream = poifs.createDocumentInputStream("Workbook"); factory.processRecords(documentInputStream);