poi入门

03版本  new HSSWorkbook

 public void TestWrite03() throws IOException {
//        创建工作铺   03版本 HSSFWorkbook() 后缀名.xls
        Workbook workbook = new HSSFWorkbook();
//        创建工作表
        Sheet sheet = workbook.createSheet("人数表");
//        创建一行
        Row row1 = sheet.createRow(0);
//        创建一个单元格
//        1-1
        Cell cell11 = row1.createCell(0);
        cell11.setCellValue("今日观众");
//        1-2
        Cell cell12 = row1.createCell(1);
        cell12.setCellValue("666");
//        创建第二行
        Row row2 = sheet.createRow(1);
//        2-1
        Cell row2Cell21 = row2.createCell(0);
        row2Cell21.setCellValue("昨日观众");
//        2-2
        Cell row2Cell22 = row2.createCell(1);
        row2Cell22.setCellValue("777");

//        生成一张表 io流 03版的就是  xls结尾
        FileOutputStream fileOutputStream = new FileOutputStream(path + "第一个excel.xls");
//生成一张表
        workbook.write(fileOutputStream);
//        关闭流
        fileOutputStream.close();
        System.out.println("文件生成完毕");
    }

07版本   new XSSFWorkbook

public void TestWrite07() throws IOException {
//        创建工作铺  07 XSSFWorkbook() 后缀名.xlsx
        Workbook workbook = new XSSFWorkbook();
//        创建工作表
        Sheet sheet = workbook.createSheet("人数表");
//        创建一行
        Row row1 = sheet.createRow(0);
//        创建一个单元格
//        1-1
        Cell cell11 = row1.createCell(0);
        cell11.setCellValue("今日观众");
//        1-2
        Cell cell12 = row1.createCell(1);
        cell12.setCellValue("666");
//        创建第二行
        Row row2 = sheet.createRow(1);
//        2-1
        Cell row2Cell21 = row2.createCell(0);
        row2Cell21.setCellValue("昨日观众");
//        2-2
        Cell row2Cell22 = row2.createCell(1);
        row2Cell22.setCellValue("777");

//        生成一张表 io流 03版的就是  xls结尾
        FileOutputStream fileOutputStream = new FileOutputStream(path + "第二个excel.xlsx");
//生成一张表
        workbook.write(fileOutputStream);
//        关闭流
        fileOutputStream.close();
        System.out.println("文件生成完毕");
    }

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值