develog

poi 대용량 엑셀 write 본문

Dev/Java

poi 대용량 엑셀 write

냐옴 2013. 1. 8. 10:07

 

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 TestMain {

    public static void main(String[] args) throws Throwable {
        
        Workbook wb = new SXSSFWorkbook(1000); // keep 100 rows in memory, exceeding rows will be flushed to disk
        Sheet sheet = wb.createSheet();
        
        for (int i = 0; i < 1048576; i++) {
            System.out.print(i + " => ");
            Row row = sheet.createRow(i);
            
            for (int j = 0; j < 50; j++) {
                System.out.print(j + "\t");
                Cell cell = row.createCell(j);
                String address = new CellReference(cell).formatAsString();
                cell.setCellValue(address);
            }
            
            System.out.println();
        }

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

}

'Dev > Java' 카테고리의 다른 글

XML DOM  (0) 2013.01.27
AES  (0) 2013.01.27
Quartz job fire manually  (0) 2012.12.18
Quartz - Defining a Job  (0) 2012.12.14
java get ip  (0) 2012.12.14
Comments