如何从大型 Excel 文件复制整个工作表而不使用 Apache POI 解析它们? [英] How to copy entire sheets from large excel files without parsing them using Apache POI?

查看:25
本文介绍了如何从大型 Excel 文件复制整个工作表而不使用 Apache POI 解析它们?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是正式用户的新手,我总是在这里找到答案,但现在我不得不问.

I am new as an official user, I always found my answers here but now I have got to ask.

我正在使用最新的 apache-poi 3.8 版本(从 2012 年 3 月 26 日开始),我必须使用多个工作表操作单个文件,其中只有一个包含大量数据(超过 1000 列和 10 000行).

I am working with the last apache-poi 3.8 release (from 2012/03/26) and I have to manipulate a single file with multiple sheets in which only one contains a big amount of data (over 1000 columns and 10 000 rows).

我只需要在大表中添加更多列.因此,使用现有的工具,我应该使用 SAX 读取它并使用 SXSSF 重写它.

I only need to had more columns to the big sheet. Therefore, with the current tools that exist I should use SAX to read it and SXSSF to rewrite it.

Excel 文件已经在每个工作表中预先格式化为不同的样式和图像,因此能够在没有大工作表的情况下制作文件副本会很有帮助.

The Excel file is already preformatted with different styles and images in every sheet therefore it will be helpful to be able to make a copy of the file without the big sheet.

我的问题是:如何在不解析的情况下使用 SAX(来自 中的输入流)制作工作表的副本?我试着在这里但是 XSSFWorkbook 中的字段 sheets 的可见性设置为私有.

There goes my question: How can I make a copy of sheet with SAX (from the input stream in ) without parsing it? I tried to do like in here but the field sheets in XSSFWorkbook has a visibility set to private.

如果 POI 开发人员的未来计划中有类似 SXSSFWriter.SheetIterator 之类的东西,那真是太棒了.

The awesome thing would be to have something like a SXSSFWriter.SheetIterator if it is in future plans for POI Developers.

感谢阅读,

亚瑟

**更新**

**Update**

文件太大,无法作为普通 XSSFWorkbook 打开(OutOfMemoryException).是否可以从 InputStream 创建 XSSFSheet?如下所示:

The file is too big to be able to open it as a common XSSFWorkbook (OutOfMemoryException). Could it be possible to create and XSSFSheet from an InputStream? Like in the following:

  XSSFReader.SheetIterator iter = (XSSFReader.SheetIterator) xssfReader
            .getSheetsData();
    int index = 0;
    while (iter.hasNext()) {
        InputStream stream = iter.next();
        String sheetName = iter.getSheetName();
        if (!sheetName.equalsIgnoreCase("BigSheetThatIDontWant")) {
            Sheet newSheet = new XSSFSheet(stream);
            stream.close();
        }
        ++index;
    }

非常感谢您的回答.

推荐答案

您必须阅读该文件.

关于第二个问题见公共 java.util.Iterator<XSSFSheet>XSSFWorkbook.iterator()

Allows foreach loops:

 XSSFWorkbook wb = new XSSFWorkbook(package);
 for(XSSFSheet sheet : wb){

 }

这篇关于如何从大型 Excel 文件复制整个工作表而不使用 Apache POI 解析它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆