Created
September 3, 2015 07:16
-
-
Save erikwj/733ef4129d3d09f6f43a to your computer and use it in GitHub Desktop.
create large excel files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
import java.io.FileOutputStream | |
import java.io.File | |
object StreamingExcel { | |
def main(args: Array[String]): Unit = { | |
val wb = new SXSSFWorkbook(10); // keep 10 rows in memory, exceeding rows will be flushed to disk | |
val sh = wb.createSheet(); | |
for (rownum ← 0 to 50000) { | |
val row = sh.createRow(rownum); | |
for (cellnum ← 0 to 60) { | |
val cell = row.createCell(cellnum); | |
val address = new CellReference(cell).formatAsString(); | |
cell.setCellValue(address); | |
} | |
} | |
val out = new FileOutputStream(new File("~/data/sxssf.xlsx")); | |
wb.write(out); | |
out.close(); | |
// dispose of temporary files backing this workbook on disk | |
wb.dispose(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment