//Workbook wb = new XSSFWorkbook();
//FileOutputStream fileOut = new FileOutputStream("E:\\standarcode\\workbook.xlsx");
Workbook wb = new HSSFWorkbook();
FileOutputStream fileOut = new FileOutputStream("E:\\standarcode\\workbook.xls");
Sheet sheet1 = wb.createSheet("new sheet");
//创建一行
Row row=sheet1.createRow(0);
//第一个单元格,没有格式化
Cell cell = row.createCell(0);
cell.setCellValue(new Date());
//创建格式,可用于单元格
CreationHelper createHelper = wb.getCreationHelper();
CellStyle cellStyle = wb.createCellStyle();
cellStyle.setDataFormat(
createHelper.createDataFormat().getFormat("yyyy-mm-dd hh:mm:ss"));
//第二个单元格
cell = row.createCell(1);
cell.setCellValue(new Date());
cell.setCellStyle(cellStyle);
//you can also set date as java.util.Calendar
//第三个单元格
cell = row.createCell(2);
cell.setCellValue(Calendar.getInstance());
cell.setCellStyle(cellStyle);
//写到文件里面,并释放资源
wb.write(fileOut);
fileOut.close();
wb.close();
java POI创建Excel单元格并填充时间数据
最新推荐文章于 2024-04-26 15:44:16 发布