Poi和easyExcel

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.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值