zoukankan      html  css  js  c++  java
  • java

    <dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi</artifactId>
    <version>3.14</version>
    </dependency>

    <!-- ooxml -->
    <dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml</artifactId>
    <version>3.14</version>
    </dependency>

    Workbook workbook = WorkbookFactory.create(file.getInputStream());可以兼容xls 和xlsx 文件
    Sheet sheetAt = workbook.getSheetAt(0);  获取sheet 索引为0的
    Row row = sheetAt.getRow(0);  获取第几行
    int row = sheetAt.getLastRowNum();  获取最后一行的索引
    Row row = sheetAt.createRow(1);  创建不存在的行索引  、、 默认为空的单元格都需要创建
    Cell cell = row.createCell(1);  创建行的第几个单元格  
    Cell cell0 = row.getCell(0);  获取行的第几个单元格 就是单元格值
    cell.setCellValue("h2");  设置单元格值

    写入文件时,先打开file;
    workbook.write(fileOutputStream);  写入excel 文件

    打开流文件,及时关闭
  • 相关阅读:
    docker安装mtproto及报错解决方案
    Centos7下创建和管理用户
    GitHub项目绑定自己的域名
    navicate远程连接mysql8.0失败
    Java反射
    Spring AOP
    Spring注解
    学习进度笔记20
    学习进度笔记19
    学习进度笔记18
  • 原文地址:https://www.cnblogs.com/pengranxindong/p/10193215.html
Copyright © 2011-2022 走看看