기타2012. 2. 9. 14:32


import java.io.FileOutputStream;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellReference;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;

public class POITest {
 
    public static void main(String[] args) throws Throwable {
     
        Workbook 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 < 1000000; 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);
               
            }

        }

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

}


주석에 있는 설명대로 100 row가 넘어가면 자동으로 메모리에서 디스크로 flush된다.

테스트에 쓰인 버젼은 3.8 beta5다.

Posted by 미랭군