实例地址: http://download.csdn.net/detail/ht_00001/9520917
/**创建文件*/FileOutputStream fileOutput = new FileOutputStream(path);
Workbook wb =null;
if(path.endsWith(".xls")){
wb = new HSSFWorkbook();
}else if(path.endsWith(".xlsx")){
wb = new XSSFWorkbook();
}
/**创建Sheet*/
Sheet sheet1 = wb.createSheet("sheet1");
String safeName = WorkbookUtil.createSafeSheetName("[0'Brien's sales*?]");
Sheet sheet2 = wb.createSheet(safeName);
CreationHelper createHelper = wb.getCreationHelper();
/**创建行*/
Row row = sheet1.createRow(0);
/**创建单元格*/
Cell cell = row.createCell(0);
/**单元格赋值*/
cell.setCellValue(0);
row.createCell(1).setCellValue(1.2);
/**设置样式*/
CellStyle style = wb.createCellStyle();
style.setAlignment(CellStyle.ALIGN_CENTER);
style.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM);
/**给单元格设置样式*/
row.createCell(1).setCellStyle(style);