POI
POI将文件数据一次性全部加载到内存中,EasyExcel是从磁盘上一行行读取数据,逐个解析。
POI[03.xls(HSSWorkbook),07xlsx(XSSWorkbook),07xlsx加强(SXSSWorkbook)]
1.引入依赖
<!--xls(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>
<!--junit-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
</dependency>
2. 写数据
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.joda.time.DateTime;
import org.junit.Test;
import java.io.*;
public class ExcelWriteTest {
String PATH="E:\\springboot_ssm\\";
@Test
public void testWrite03() throws Exception {
Workbook workbook=new HSSFWorkbook();
Sheet sheet=workbook.createSheet("03表");
//每行
Row row1=sheet.createRow(0);
//每行的单元格
Cell cell11 = row1.createCell(0);
cell11.setCellValue("新增");
Cell cell12 = row1.createCell(1);
cell12.setCellValue(6);
Row row2=sheet.createRow(1);
Cell cell21 = row2.createCell(0);
cell21.setCellValue("时间");
Cell cell22 = row2.createCell(1);
String s = new DateTime().toString("yyyy-MM-dd HH:mm:ss");
cell22.setCellValue(s);
FileOutputStream fileOutputStream = new FileOutp