zoukankan      html  css  js  c++  java
  • 使用POI创建word表格-在表格单元格中创建子表格

    要实现的功能如下:表格中的单元格中有子表格

    实现代码如下:

                        XWPFParagraph cellPara = row.getCell(j).getParagraphArray(0);  //row.getCell(j)指的是外部表格的单元格
                        cellPara.setAlignment(ParagraphAlignment.CENTER);
                        //表格名字
                        cellPara.createRun().setText(“表格名称”);
                         
                        XWPFTable cellTable = row.getCell(j).insertNewTbl(cellPara.getCTP().newCursor());  //在此游标处插入新表格
                        cellTable.getCTTbl().addNewTblPr().addNewTblBorders().addNewLeft()
    .setVal(org.openxmlformats.schemas.wordprocessingml.x2006.main.STBorder.SINGLE); cellTable.getCTTbl().getTblPr().getTblBorders().addNewRight()
    .setVal(org.openxmlformats.schemas.wordprocessingml.x2006.main.STBorder.SINGLE); cellTable.getCTTbl().getTblPr().getTblBorders().addNewTop()
    .setVal(org.openxmlformats.schemas.wordprocessingml.x2006.main.STBorder.SINGLE); cellTable.getCTTbl().getTblPr().getTblBorders().addNewBottom()
    .setVal(org.openxmlformats.schemas.wordprocessingml.x2006.main.STBorder.SINGLE); cellTable.getCTTbl().getTblPr().getTblBorders().addNewInsideH()
    .setVal(org.openxmlformats.schemas.wordprocessingml.x2006.main.STBorder.SINGLE); cellTable.getCTTbl().getTblPr().getTblBorders().addNewInsideV()
    .setVal(org.openxmlformats.schemas.wordprocessingml.x2006.main.STBorder.SINGLE); // 此处为绘制子表格代码,省略......
                // 内部子表格居中: cellTable.getCTTbl().getTblPr().addNewJc().setVal(STJc.CENTER);
    // 内部表格水平居中 row.getCell(j).setVerticalAlignment(XWPFVertAlign.CENTER); // 单元格垂直居中
  • 相关阅读:
    (周日赛) Average is not Fast Enough!
    过山车
    (寒假CF3)B
    (寒假CF3)坑坑坑
    (周六赛1)Sum it up
    畅通工程
    vue 动态添加form表单item 校验问题
    html2canvas转pdf分页隔断问题处理
    vue中html转pdf并下载功能
    一个简单的滑动溢出效果
  • 原文地址:https://www.cnblogs.com/fengbing9891/p/10030756.html
Copyright © 2011-2022 走看看