如何通过java创建一个空白的表格在项目中

这里的filename是目录的名称,XSSFWorkbook对应的是2007版本的,也可以将其换成2003版本HSSFWorkbook。
具体流程是首先创建一个excel对象,然后可以创建sheet,创建row以及cell,其中也可以设置颜色,样式等信息,最后通过new 文件输出流,将其输出到传入的目录下

/**

  • 创建空白的excel文件

  • @param filename

  • @throws IOException
    */
    public static void CreateBlankExcel(String filename) throws IOException {

    // Create Blank workbook
    XSSFWorkbook workbook = new XSSFWorkbook();
    Sheet sheet = workbook.createSheet();
    XSSFCellStyle cellStyle = workbook.createCellStyle();
    XSSFFont font = workbook.createFont();
    font.setColor(Font.COLOR_RED);
    cellStyle.setFont(font);
    Row row = sheet.createRow(0);
    Cell cell0 = row.createCell(0);
    cell0.setCellValue(“序号”);
    Cell cell1 = row.createCell(1);
    cell1.setCellValue(“组织*”);
    Cell cell2 = row.createCell(2);
    cell2.setCellValue(“111*”);
    Cell cell3 = row.createCell(3);
    cell3.setCellValue(“222*”);
    Cell cell4 = row.createCell(4);
    cell4.setCellValue(“333*”);
    Cell cell5 = row.createCell(5);
    cell5.setCellValue(“收方户名*”);
    Cell cell6 = row.createCell(6);
    cell6.setCellValue(“444*”);
    Cell cell7 = row.createCell(7);
    cell7.setCellValue(“金额*”);
    Cell cell8 = row.createCell(8);
    cell8.setCellValue(“555*”);
    Cell cell9 = row.createCell(9);
    cell9.setCellValue(“666*”);
    Cell cell10 = row.createCell(10);
    cell10.setCellValue(“777”);
    Cell cell11 = row.createCell(11);
    cell11.setCellValue(“5”);
    Cell cell12 = row.createCell(12);
    cell12.setCellValue(“5”);
    Cell cell13 = row.createCell(13);
    cell13.setCellValue(“5”);
    Cell cell14 = row.createCell(14);
    cell14.setCellValue(“5”);
    Cell cell15 = row.createCell(15);
    cell15.setCellValue(“用途”);
    Cell cell16 = row.createCell(16);
    cell16.setCellValue(“5”);
    Cell cell17 = row.createCell(17);
    cell17.setCellValue(“5”);
    Cell cell18 = row.createCell(18);
    cell18.setCellValue(“5”);
    Cell cell19 = row.createCell(19);
    cell19.setCellValue(“5”);
    Cell cell20 = row.createCell(20);
    cell20.setCellValue(“5”);
    Cell cell21 = row.createCell(21);
    cell21.setCellValue(“5”);
    // Create file system using specific name
    FileOutputStream out = new FileOutputStream(new File(filename));
    // write operation workbook using file out object
    workbook.write(out);
    out.close();
    }

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值