1. POI
2.
3. 添加 jar 包
4. <dependencies>
5. <!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
6. <dependency>
7. <groupId>org.apache.poi</groupId>
8. <artifactId>poi</artifactId>
9. <version>3.9</version>
10. </dependency>
11. <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
12. <dependency>
13. <groupId>org.apache.poi</groupId>
14. <artifactId>poi-ooxml</artifactId>
15. <version>3.9</version>
16. </dependency>
17. 生成日期
18. <dependency>
19. <groupId>joda-time</groupId>
20. <artifactId>joda-time</artifactId>
21. <version>2.10.1</version>
22. </dependency>
23. 生成测试类
24. <dependency>
25. <groupId>junit</groupId>
26. <artifactId>junit</artifactId>
27. <version>4.12</version>
28. </dependency>
29. 代码编写
30. //1.创建一个工作簿
31. Workbook workbook = new XSSFWorkbook();
32. //2.创建一个工作表
33. Sheet sheet = workbook.createSheet("狂神观众统计表");
34. //3.创建一个行
35. Row row1 = sheet.createRow(0);
36. //4.创建一个单元格
37. Cell cell11 = row1.createCell(0);
38. cell11.setCellValue("今日新增观众");
39. //(1,2)
40. Cell cell12 = row1.createCell(1);
41. cell12.setCellValue(666);
42. //第二行(2,1)
43. Row row2 = sheet.createRow(1);