POI和EasyExcel的使用

POI

1.基本功能

结构:

HSSF — 提供读写Mircrosft Excel格式档案功能(03版)

XSSF — 提供读写Mircrosft Excel OOXML格式档案的功能(07版)

HWPF — 提供读写Mircrosft World格式档案的功能

HSLF — 提供读写Mircrosft PowerPoint格式档案的功能

HDGF — 提供读写Mircrosft Visio格式档案的功能

2.POI — 导出

导入依赖

    <dependencies>
        <!--xls(03)-->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.9</version>
        </dependency>

        <!--xls(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>

        <!--test-->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>
    </dependencies>

基础代码

public class ExcelWriteTest {

    String PATH = "E:\\hanfeng\\";

    @Test
    public void testWrite03() throws IOException {
        // 1.创建工作簿
        Workbook workbook = new HSSFWorkbook();
        // 2.创建一个工作表
        Sheet sheet = workbook.createSheet("狂神观众统计表");
        // 3.创建一个行
        Row row1 = sheet.createRow(0);
        // 4.创建一个单元格
        Cell cell11 = row1.createCell(0);
        cell11.setCellValue("今日新增观众");

        Cell cell12 = row1.createCell(1);
        cell12.setCellValue(666);

        // 第二行
        Row row2 = sheet.createRow(1);
        Cell cell21 = row2.createCell(0);
        cell21.setCellValue("统计时间");
        Cell cell22 = row2.createCell(1);
        String time = new DateTime().toString("yyyy-MM-ss HH:mm:ss");
        cell22.setCellValue(time);

        // 生成一张表(IO 流)
        FileOutputStream fileOutputStream = new FileOutputStream(PATH + "狂神观众统计表03.xls");
        workbook.write(fileOutputStream);
        // 关闭流
        fileOutputStream.close();
        System.out.println("03生成完毕");

    }

    @Test
    public void testWrite07() throws IOException {
        // 1.创建工作簿
        Workbook workbook = new XSSFWorkbook();
        // 2.创建一个工作表
        Sheet sheet = workbook.createSheet("狂神观众统计表");
        // 3.创建一个行
        Row row1 = sheet.createRow(0);
        // 4.创建一个单元格
        Cell cell11 = row1.createCell(0);
        cell11.setCellValue("今日新增观众");

  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值