public void createWorkBook() throws IOException { 
 //建excel活頁簿 
 XSSFWorkbook workBook = new XSSFWorkbook(); 
 //建第一個sheet,命名為 new sheet 
 XSSFSheet sheet = workBook.createSheet("first sheet"); 
 // 建一row,在sheet上 
 Row row = sheet.createRow(0); 
 // 在row上建一個cell
 Cell cell = row.createCell(0); 
 //設cell裡的值 
 cell.setCellValue("第一個cell"); 
 // Or do it on one line. 
 row.createCell(1).setCellValue("第一列的第2個cell"); 
 row.createCell(2).setCellValue(new Date()); 
 row.createCell(3).setCellValue(true); 
 row.createCell(4).setCellValue(2); 
 //file命名為myExcekbook.xlsx 
 FileOutputStream fileOut = new FileOutputStream("d:/myExcekbook.xlsx"); 
 // 把workBook寫進FileOutputStream
 workBook.write(fileOut); 
 //關閉FileOutputStream
 fileOut.close(); 
}