public void testWrite03() throws IOException {
String PATH="D:\\java\\Project\\jx_xunshi_wj\\discipline-web\\src\\main\\webapp\\upload\\2022\\12\\06\\";
//创建一个工作簿
Workbook workbook = new HSSFWorkbook();
//创建一个工作表
Sheet sheet = workbook.createSheet("哈哈");
//创建一个行
Row row1 = sheet.createRow(0);
//创建2个单元格(1,1)(1,2)
Cell cell11 = row1.createCell(0);
Cell cell12 = row1.createCell(1);
String time = new DateTime().toString("yyyy-MM-dd HH:mm:ss");
//设置两个单元格的值
cell11.setCellValue("统计表");
cell12.setCellValue(time);
//创建第二行
Row row2 = sheet.createRow(1);
//创建2个单元格(2,1)(2,2)
Cell cell21 = row2.createCell(0);
Cell cell22 = row2.createCell(1);
cell21.setCellValue("新增人数");
cell22.setCellValue("777");
//生成一张表(IO流)
FileOutputStream fileOutputStream = new FileOutputStream(PATH+"03.xls");
//输出
workbook.write(fileOutputStream);
//关闭流
fileOutputStream.close();
System.out.println("文件生成成功:"+PATH);
}
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
</dependency>