EasyExcel学习笔记
官方地址:https://www.yuque.com/easyexcel/doc/easyexcel
学习EasyExcel之前,首先要学习Apache poi
Apache poi
1、创建springboot项目,然后导入依赖.
poi是03版本,然后他的excel结尾是xls
poi-ooxml是07版本,excel结尾是xlsx
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.9</version>
</dependency>
<!– https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml –>
<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.5</version>
</dependency>
2、写03版本的excel
HSSFWorkbook是创建03版本的对象。而07版本的是XSSFWorkbook
@Test
public static void ExcelWrite03()throws Exception{
Workbook workbook=new HSSFWorkbook();
Sheet sheet=workbook.createSheet("卢航统计表");
//第一行
Row row=sheet.createRow(0);
Cell cell=row.createCell(0);
cell.setCellValue("姓名");
Cell cell1=row.createCell(1);
cell1.setCellValue("出生日期");
//第二行
Row row1=sheet.createRow(1);
Cell cell2 = row1.createCell(0);
cell2.setCellValue("1111");
Cell cell3 = row1.createCell(1);
cell3.setCellValue(new DateTime().toString("yyyy-MM-dd HH-mm-ss"));
FileOutputStream fileOutputStream=new FileOutputStream(path+"luhang03.xls");
workbook.write(fileOutputStream);
fileOutputStream.close();
System.out.println("导出成功");
}
3、写07版本的excel
@Test
public static void ExcelWrite07()throws Exception{
Workbook workbook=new XSSFWorkbook();
Sheet sheet=workbook.createSheet("卢航统计表");
//第一行
Row row=sheet.createRow(0);
Cell cell=row.createCell(0);
cell.setCellValue("姓名");
Cell cell1=row<