Poi和easyExcel
对Excel进行操作 把数据变为excel或者把excel写入数据库
poi的原理是直接先把数据加载到内存里面 这样很消耗内存 可能造成oom(内存溢出)
而easyExcel是一行一行进行解析 所以说它是针对poi优化的框架
其实excel有两个重要的版本 一个03 一个07 对应的后缀为xls 和xlsx 依赖分别是poi和poi-ooxml
03版本有65536行的一个限制 而07没有
excel由工作簿 工作表 行 列 组成
#03版本
@Test
public void test03() throws Exception {
String path="E:\\idea\\ideaspace\\poi\\";
Workbook workbook=new HSSFWorkbook();
Sheet sheet=workbook.createSheet("张宇航的表");
Row row=sheet.createRow(0);
Cell cell=row.createCell(0);
cell.setCellValue("1111");
Cell cell1=row.createCell(1);
cell1.setCellValue("111");
Row row1=sheet.createRow(1);
Cell cell2=row1.createCell(0);
cell2.setCellValue("1111");
Cell cell3=row1.createCell(1);
String s = new DateTime().toString("yyyy-MM-dd HH:mm:ss");
cell3.setCellValue(s);
FileOutputStream fileOutputStream = new FileOutputStream(path + "张宇航.xls");
workbook.write(fileOutputStream);
fileOutputStream.close();
System.out.println("文件生成完毕");
}
#07版本
@Test
public void test07() throws Exception {
String path="E:\\idea\\ideaspace\\poi\\";
Workbook workbook=new XSSFWorkbook();
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.