Skip to content

Instantly share code, notes, and snippets.

@zhangxu
Last active October 13, 2015 22:14
Show Gist options
  • Save zhangxu/dfff9660734a4182c7c7 to your computer and use it in GitHub Desktop.
Save zhangxu/dfff9660734a4182c7c7 to your computer and use it in GitHub Desktop.
Generating Excel Workbook Using Apache POI
import org.apache.poi.hssf.usermodel._
import org.apache.poi.ss.util._
import java.io._
val fileOut = new FileOutputStream("/tmp/workbook.xls")
val wb = new HSSFWorkbook
val sheet1 = wb.createSheet(WorkbookUtil.createSafeSheetName("new sheet"))
val sheet2 = wb.createSheet(WorkbookUtil.createSafeSheetName("second sheet"))
val row1 = sheet1.createRow(0)
val row2 = sheet2.createRow(0)
val cell_1 = row1.createCell(0)
val cell_2 = row2.createCell(0)
cell_1.setCellValue("This is a test of fonts");
cell_2.setCellValue(3.14)
wb.write(fileOut);
fileOut.close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment