2

我正在尝试使用 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);

但我得到了例外

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

据说此异常已在 3.5 中修复,但是,我使用的是 3.6,并且我还尝试了从 POI 拉出最新的主干,但仍然是同样的问题。

我尝试将文件缩小到只有几行但同样的错误。以前有没有人处理过这个问题?

谢谢,杰夫

4

2 回答 2

1

您应该使用带有DocumentInputStream类型的EventRecordFactory.processRecords方法作为它的参数。(而不是纯)。FileInputStream

POIFSFileSystem poifs = new POIFSFileSystem(input);
DocumentInputStream documentInputStream = poifs.createDocumentInputStream("Workbook");
factory.processRecords(documentInputStream);
于 2013-09-25T08:46:41.750 回答
0

您在 excel 文件中是否有任何大注释。如果是这样,您可以在删除评论后尝试。

于 2010-02-01T21:55:26.223 回答