POI-Easyexcel01
配置
<dependencies>
<!--xls03-->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.9</version>
</dependency>
<!--xls07-->
<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>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
</dependencies>
写操作
POI已经完成了对excel对象的抽象工作
对象
- 工作簿:workbook
- 工作表:sheet
- 行:row
- 列:cell
excel03版(xls)
public void testWrite03() throws Exception {
//1、创建一个工作簿03
Workbook workbook = new HSSFWorkbook();
//2、创建一个工作表
Sheet sheet = workbook.createSheet("帅b统计表");
//3、创建一个行(1,1)
Row row1 = sheet.createRow(0);
//4、创建一个单元格
Cell cell1 = row1.createCell(0);
cell1.setCellValue("今日的新增帅b");
//(1,2)
Cell cell2 = row1.createCell(1);
cell2.setCellValue(666);
//(2,1)
Row row2 = sheet.createRow(1);
Cell cell21 = row2.createCell(0);
cell21.setCellValue("统计时间");
//(2,2)
Cell cell22 = row2.createCell(1);
String time = new DateTime().toString("yyyy-MM-dd HH:mm:ss");
cell22.setCellValue(time);
//生成一张表(IO 流)
FileOutputStream fileOutputStream = new FileOutputStream(PATH + "帅B统计表.xls");
//输出
workbook.write(fileOutputStream);
//关闭流
fileOutputStream.close();
System.out.println("表生成完毕");
}
excel07版(xls)
public void testWrite07() throws Exception {
//1、创建一个工作簿07
Workbook workbook = new XSSFWorkbook();
//2、创建一个工作表
Sheet sheet = workbook.createSheet("帅b统计表");
//3、创建一个行(1,1)
Row row1 = sheet.createRow(0);
//4、创建一个单元格
Cell cell1 = row1.createCell(0);
cell1.setCellValue("今日的新增帅b");
//(1,2)
Cell cell2 = row1.createCell(1);
cell2.setCellValue(666);
//(2,1)
Row row2 = sheet.createRow(1);
Cell cell21 = row2.createCell(0);
cell21.setCellValue("统计时间");
//(2,2)
Cell cell22 = row2.createCell(1);
String time = new DateTime().toString("yyyy-MM-dd HH:mm:ss");
cell22.setCellValue(time);
//生成一张表(IO 流)
FileOutputStream fileOutputStream = new FileOutputStream(PATH + "帅B统计表.xlsx");
//输出
workbook.write(fileOutputStream);
//关闭流
fileOutputStream.close();
System.out.println("表生成完毕");
}
``