poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Warren Tang <warren.c.t...@gmail.com>
Subject HSSF eventusermodel & field read/write problem.
Date Mon, 05 Mar 2012 00:27:31 GMT
Hi, everybody

I came across performance issue when reading large Excel97 files with
usermodel. When the file size is over 15MB, the HSSFWorkbook's constructor
never returns or returns with an OutOfMemoryError (GC overhead limit

So I've been trying to use eventusermodel to reduce the memory footprint,
but I have problem to pertain the value of the modified fields. Below is
the code. I need the modified value of an instance field (modifyMe); but
the value is always 0 rather than 100 which is what I want.

----------------------------- HssfEventApiTest.java
import static org.junit.Assert.*;
import java.io.IOException;
import java.io.InputStream;
import org.apache.poi.hssf.eventusermodel.HSSFEventFactory;
import org.apache.poi.hssf.eventusermodel.HSSFListener;
import org.apache.poi.hssf.eventusermodel.HSSFRequest;
import org.apache.poi.hssf.record.EOFRecord;
import org.apache.poi.hssf.record.Record;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.junit.Test;
import com.tangcs.zhc.server.ServerTestBase;

public class HssfEventApiTest extends ServerTestBase
        implements HSSFListener
    int modifyMe;  // The instance field to be modified by the listener

    public void processRecord(Record record)
        switch (record.getSid())
            case EOFRecord.sid:
                modifyMe = 100;      //Modified here.
                System.out.println("End of file.");

    @Test public void testEventApi() throws IOException
        InputStream fin = getResourceAsStream("xls/exam-results-min.xls");
        POIFSFileSystem poifs = new POIFSFileSystem(fin);
        InputStream din = poifs.createDocumentInputStream("Workbook");
        HSSFRequest req = new HSSFRequest();
        req.addListenerForAllRecords(new HssfEventApiTest());
        HSSFEventFactory factory = new HSSFEventFactory();
        factory.processEvents(req, din);

        System.out.println("modifyMe = " + modifyMe);
        assertEquals(100, modifyMe);     //Fails here with actual == 0;
//          The stdout is:
//          End of file.
//          End of file.
//          modifyMe = 0


Warren Tang <http://blog.tangcs.com>

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message