poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From peruzzo <m.peruzz...@yahoo.com>
Subject Re: Apache POI works but it uses too RAM: is it a limit of your library?
Date Fri, 29 Mar 2013 09:12:18 GMT
Thanks, I found a method on your web site but I don't understand like I can
use SXSSF and I am afraid to have to rewrite all my previously code (it has
many rows of code). For example, like can I use this following code? I don't
see any input array! Could you give to me an example of writing and
rewriting please?

public static void metodo() throws Throwable {

		SXSSFWorkbook wb = new SXSSFWorkbook(100); // keep 100 rows in memory,
													// exceeding rows will be
													// flushed to disk
		Sheet sh = wb.createSheet();
		for (int rownum = 0; rownum < 1000; rownum++) {
			Row row = sh.createRow(rownum);
			for (int cellnum = 0; cellnum < 10; cellnum++) {
				Cell cell = row.createCell(cellnum);
				String address = new CellReference(cell).formatAsString();
				cell.setCellValue(address);
			}

		}

		// Rows with rownum < 900 are flushed and not accessible
		for (int rownum = 0; rownum < 900; rownum++) {
			Assert.assertNull(sh.getRow(rownum));
		}

		// ther last 100 rows are still in memory
		for (int rownum = 900; rownum < 1000; rownum++) {
			Assert.assertNotNull(sh.getRow(rownum));
		}

		FileOutputStream out = new FileOutputStream("sxssf.xlsx");
		wb.write(out);
		out.close();

		// dispose of temporary files backing this workbook on disk
		wb.dispose();
}



--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Apache-POI-works-but-it-uses-too-RAM-is-it-a-limit-of-your-library-tp5712425p5712446.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Mime
View raw message