org.apache.poi


从apache.poi官方文档中也能看得到

 1 public static void creatWorkbook()throws Exception{
 2         // 创建工作薄
 3         Workbook wb = new HSSFWorkbook();
 4         // 创建表
 5         CreationHelper createHelper = wb.getCreationHelper();
 6         Sheet sheet = wb.createSheet("new sheet");
 7         // 创建第一行 ***************************
 8         Row row = sheet.createRow(0);
 9         // 创建单元格
10         Cell cell = row.createCell(0);
11         // 插入单元格数值 (整数、小数、字符串、布尔型)
12         cell.setCellValue(1);
13         row.createCell(1).setCellValue(1.2);
14         row.createCell(2).setCellValue(createHelper.createRichTextString("This is a string"));
15         row.createCell(3).setCellValue(true);
16         // 创建第二行 * 时间 *************************
17         Row row1 = sheet.createRow(1);
18         Cell cell1 = row1.createCell(0);
19         String localData = LocalDate.now().toString();
20         cell1.setCellValue(createHelper.createRichTextString(localData));
21 
22 
23         CellStyle cellStyle = wb.createCellStyle();
24         cellStyle.setDataFormat(createHelper.createDataFormat().getFormat("m/d/yy h:mm"));
25         cell1 = row1.createCell(1);
26         cell1.setCellValue(new Date());
27         cell1.setCellStyle(cellStyle);
28 
29         //you can also set date as java.util.Calendar
30         cell1 = row1.createCell(2);
31         cell1.setCellValue(Calendar.getInstance());
32         cell1.setCellStyle(cellStyle);
33         row1.createCell(3).setCellType(CellType.ERROR);
34 
35         // 输出文件
36         try  (OutputStream fileOut = new FileOutputStream("D:\\资料\\exl\\workbook.xls")) {
37             wb.write(fileOut);
38         }
39     }