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); // 单元格垂直居中
  • 相关阅读:
    Python学习————正向代理和反向代理
    Python学习————drf(三)
    Python学习————drf(二)
    Python学习————drf(一)
    Python学习————python基础复习(四)
    Python学习————python基础复习(三)
    Python学习————python基础复习(二)
    Python学习————python基础复习(一)
    Python学习————Django
    51Nod1523 非回文
  • 原文地址:https://www.cnblogs.com/fengbing9891/p/10030756.html
Copyright © 2011-2022 走看看