Java多个ppt合并脚本_java中poi自动生成ppt的表格,怎样合并行列?

这篇博客介绍了如何使用Java的POI库创建PPT,并展示了如何设置单元格内容,创建合并单元格以展示总计和百分比。通过示例代码,展示了创建Excel工作簿,设置单元格样式,以及生成合并的表格区域。
摘要由CSDN通过智能技术生成

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

// 不跨单元格显示的数据,如:分两行,上一行分别两格为一格,下一行就为两格,“数量”,“金额”

HSSFCell cell1 = row2.createCell((short) celle);

HSSFCell cell2 = row2.createCell((short) (celle + 1));

cell1.setEncoding(HSSFCell.ENCODING_UTF_16);

cell1.setCellValue("数量");

cell1.setCellStyle(style);

cell2.setEncoding(HSSFCell.ENCODING_UTF_16);

cell2.setCellValue("金额");

cell2.setCellStyle(style);

num++;

}

// 在后面加上合计百分比

// 合计 在最后加上,还要跨一个单元格

sheet.addMergedRegion(new Region(0, (short) (2 * num + 1), 0,

(short) (2 * num + 2)));

HSSFCell cell = row.createCell((short) (2 * num + 1));

cell.setEncoding(HSSFCell.ENCODING_UTF_16);

cell.setCellValue("合计");

cell.setCellStyle(style);

HSSFCell cell1 = row2.createCell((short) (2 * num + 1));

HSSFCell cell2 = row2.createCell((short) (2 * num + 2));

cell1.setEncoding(HSSFCell.ENCODING_UTF_16);

cell1.setCellValue("数量");

cell1.setCellStyle(style);

cell2.setEncoding(HSSFCell.ENCODING_UTF_16);

cell2.setCellValue("金额");

cell2.setCellStyle(style);

// 百分比 同上

sheet.addMergedRegion(new Region(0, (short) (2 * num + 3), 0,

(short) (2 * num + 4)));

HSSFCell cellb = row.createCell((short) (2 * num + 3));

cellb.setEncoding(HSSFCell.ENCODING_UTF_16);

cellb.setCellValue("百分比");

cellb.setCellStyle(style);

HSSFCell cellb1 = row2.createCell((short) (2 * num + 3));

HSSFCell cellb2 = row2.createCell((short) (2 * num + 4));

cellb1.setEncoding(HSSFCell.ENCODING_UTF_16);

cellb1.setCellValue("数量");

cellb1.setCellStyle(style);

cellb2.setEncoding(HSSFCell.ENCODING_UTF_16);

cellb2.setCellValue("金额");

cellb2.setCellStyle(style);

FileOutputStream fileOut = new FileOutputStream("workbook.xls");

wb.write(fileOut);

fileOut.close();

System.out.print("OK");

} catch (Exception ex) {

ex.printStackTrace();

}

}

}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值