POI-Excel大資料量的寫入
阿新 • • 發佈:2020-09-03
POI-Excel大資料量的寫入
public class ExcelWriteTest { String PATH = "C:\\Users\\Kven_J\\idea-workspace\\POI-EasyExcel\\chang-poi-"; @Test public void testWrite07BigData() throws IOException { //開始時間 long begin = System.currentTimeMillis(); //建立一個工作簿 Workbook wb = newXSSFWorkbook(); //建立一個工作表 Sheet sheet = wb.createSheet(); //寫入資料 for (int rowNum = 0; rowNum < 100000; rowNum++) { Row row = sheet.createRow(rowNum); for (int cellNum = 0; cellNum < 10; cellNum++) { Cell cell = row.createCell(cellNum); cell.setCellValue(cellNum); } }//生成表(IO流) 07版本使用.xlsx結尾 FileOutputStream fileOutputStream = new FileOutputStream(PATH + "07BigData.xlsx"); wb.write(fileOutputStream); fileOutputStream.close(); //結束時間 long end = System.currentTimeMillis(); System.out.println((double) (end-begin)/1000); } @Testpublic void testWrite07BigDataS() throws IOException { //開始時間 long begin = System.currentTimeMillis(); //建立一個工作簿 Workbook wb = new SXSSFWorkbook(); //建立一個工作表 Sheet sheet = wb.createSheet(); //寫入資料 for (int rowNum = 0; rowNum < 100000; rowNum++) { Row row = sheet.createRow(rowNum); for (int cellNum = 0; cellNum < 10; cellNum++) { Cell cell = row.createCell(cellNum); cell.setCellValue(cellNum); } } //生成表(IO流) 07版本使用.xlsx結尾 FileOutputStream fileOutputStream = new FileOutputStream(PATH + "07BigDataS.xlsx"); wb.write(fileOutputStream); fileOutputStream.close(); //清除臨時檔案 ((SXSSFWorkbook)wb).dispose(); //結束時間 long end = System.currentTimeMillis(); System.out.println((double) (end-begin)/1000); } }