POI-Excel写
导入依赖
<dependencies>
<!--xlsx(03)-->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.9</version>
</dependency>
<!--xlsx(07)-->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.9</version>
</dependency>
<!--日期格式化工具-->
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.10.1</version>
</dependency>
String path ="C:\\Users\\2020\\IdeaProjects\\SpringFuXi\\poi\\src\\main\\java\\org\\example";
@Test
public void testWrite03() throws IOException {
//1.创建一个工作簿
Workbook workbook = new HSSFWorkbook();
//2.创建一个工作表
Sheet sheet = workbook.createSheet("统计表");
//3.创建一个行
Row row1 = sheet.createRow(0);
//4.创建一个单元格
Cell cell = row1.createCell(0);
cell.setCellValue("今日新增");
Cell cell1 = row1.createCell(1);
cell1.setCellValue(666);
//创建第二行
Row row2 = sheet.createRow(1);
Cell cell2 = row2.createCell(0);
cell2.setCellValue("统计时间");
Cell cell3 = row2.createCell(1);
cell3.setCellValue(new DateTime().toString("yyyy-MM-dd HH-mm-ss"));
//生成一张表 03版本就是使用xls结尾
FileOutputStream fileOutputStream = new FileOutputStream(path + "统计表03.xls");
workbook.write(fileOutputStream);
fileOutputStream.close();
System.out.println("生成完毕");
}
@Test
public void testWrite07() throws IOException {
//1.创建一个工作簿
Workbook workbook = new XSSFWorkbook();
//2.创建一个工作表
Sheet sheet = workbook.createSheet("统计表");
//3.创建一个行
Row row1 = sheet.createRow(0);
//4.创建一个单元格
Cell cell = row1.createCell(0);
cell.setCellValue("今日新增")