我正在尝试使用 POI 来读取 Excel 文件。这将是一个大文件(> 50k 行)所以我使用 eventusermodel 而不是将整个文件读入内存的更简单的 usermodel。我的代码如下所示:
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);
但我得到了异常(exception)
org.apache.poi.hssf.record.RecordFormatException: The content of an excel record cannot exceed 8224 bytes
这个异常应该在 3.5 中得到修复,但是,我使用的是 3.6,我也尝试了从 POI 获取最新的 trunk pull,但仍然是同样的问题。
我试过将文件缩小到只有几行但出现相同的错误。以前有人处理过这个问题吗?
谢谢, 杰夫
最佳答案
你应该使用 EventRecordFactory .processRecords
方法与 DocumentInputStream类型作为它的参数。 (而不是纯 FileInputStream
)。
POIFSFileSystem poifs = new POIFSFileSystem(input);
DocumentInputStream documentInputStream = poifs.createDocumentInputStream("Workbook");
factory.processRecords(documentInputStream);
关于Java Apache POI Excel读取异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2180293/