POI写入海量Excel2007

POI写入海量Excel2007
import java.io.FileOutputStream;
import java.io.OutputStream;

import org.apache.poi.xssf.streaming.SXSSFRow;
import org.apache.poi.xssf.streaming.SXSSFSheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFRow;


public class TestPOI {

	/**
	 * @param args
	 * @throws Exception 
	 */
	public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub

		OutputStream os = new FileOutputStream("D:/"+System.currentTimeMillis()+".xlsx");      
        //工作区     
		SXSSFWorkbook wb = new SXSSFWorkbook();     
        SXSSFSheet sheet= (SXSSFSheet)wb.createSheet("test");
        SXSSFRow row =null;
        for(int i=0;i<110000;i++){  
        	row = (SXSSFRow) sheet.createRow(i);    
            for(int a=0;a<10;a++){
            	 row.createCell(a).setCellValue("column"+a);    
            }
            row=null;
//            //给这一行的第一列赋值     
//            row.createCell(0).setCellValue("column1");     
//            //给这一行的第一列赋值     
//            row.createCell(1).setCellValue("column2");  
            System.out.println(i);  
        }   
        //写文件     
        wb.write(os);     
        //关闭输出流     
        os.close();    
	}

}

你可能感兴趣的:(POI写入海量Excel2007)