Hi All,

Iam trying to evaluate Apache POI so that I can use it for my project in
company.

Following is the sample program I ran with the following JVM options:
-Xms256m -Xmx1024m

import java.io.File;
import java.io.FileOutputStream;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;


public class TestExcel {
    public TestExcel() {
    }

    public static void main(String[] args) throws Exception {
        HSSFWorkbook mainWorkBook = new HSSFWorkbook();
        HSSFSheet mainSheet = mainWorkBook.createSheet();

        HSSFRow newRow = null;
        HSSFCell newCell = null;

        for (int i = 0; i < 30000; i++) {
            newRow = mainSheet.createRow(i);

            for (int j = 0; j < 255; j++) {
                newRow.createCell(j).setCellValue("Test");
            }
        }

        FileOutputStream output = new FileOutputStream(new
File("C:\\Test\\Test.xls"));
        mainWorkBook.write(output);
        output.flush();
        output.close();
    }
}


The program works fine till 20000 rows, but I get OutOfMemory exception for
30000 rows. I did search in some forums regarding this issue, but I didnt
get proper solution.

Can you guys suggest me how can I do it? Is it possible to write part of the
workbook data to the file ->  clear the workbook -> write to the file etc?

-- 
With regards,
B.R.Hima Bindu.
Yogi Berra <http://www.brainyquote.com/quotes/authors/y/yogi_berra.html>  -
"I never said most of the things I said."

Reply via email to