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); // 单元格垂直居中
  • 相关阅读:
    杭电 1521 排列组合

    杭电 1799 循环多少次?
    杭电1028 Ignatius and the Princess III(整数拆分)
    毕业论文A.1 Matlab环境配置
    Open Graphics Library初步_搭建环境_GLUT
    Open Graphics Library初步_摄影机_GLUT
    C#使用office相关com组件
    插入排序
    二叉树的四种遍历方法(递归、迭代)
  • 原文地址:https://www.cnblogs.com/fengbing9891/p/10030756.html
Copyright © 2011-2022 走看看