aspose.word 在已有模板表格中动态插入新行

通过已有模板进行进行动态行,aspose版本为21.6

问题,使用insertAfter插入新行后,没有与原表格合并,而是形成了新的表格,这明显不符合要求,最后使用克隆行的方法进行插入,与原表格完美融合

主要代码如下:

复制代码
 private void replaceExpertInfoNew(List<ErisNewExpertInfo> expertList, Document doc) {
        Bookmark realName = doc.getRange().getBookmarks().get("realName");
        //书签->-单元格->行->表格
        Row row = (Row) realName.getBookmarkStart().getParentNode().getParentNode().getParentNode();
        Table table = (Table) row.getParentNode();

        for (ErisNewExpertInfo expert : expertList) {
            Row nextRow = (Row) row.deepClone(true);
            插入一行
            table.insertAfter(nextRow, row);
            CellCollection cells = nextRow.getCells();
            int index = 0;
            for (Cell cell : cells) {
                cell.removeAllChildren();
                Paragraph paragraph = new Paragraph(doc);
                cell.appendChild(paragraph);
                switch (index) {
                    case 0:
                        paragraph.appendChild(new Run(doc, expert.getRealName()));
                        break;
                    case 1:
                        paragraph.appendChild(new Run(doc, expert.getWorkUnit()));
                        break;
                    case 2:
                        paragraph.appendChild(new Run(doc, expert.getDepartment()));
                        break;
                    case 3:
                        paragraph.appendChild(new Run(doc, expert.getPosition()));
                        break;
                    case 4:
                        paragraph.appendChild(new Run(doc, expert.getPhone()));
                        break;
                    case 5:
                        paragraph.appendChild(new Run(doc, expert.getEmail()));
                        break;
                    case 6:
                        paragraph.appendChild(new Run(doc, ExpertTypeStateEnum.getEnum(expert.getExpertTypeState()).getDescription()));
                        break;
                    default:
                        break;
                }
                index++;
            }
        }

    }

表格模板如图:

说明:模板中动态插入专家信息

相关推荐
{Hello World}20 小时前
Java抽象类与接口深度解析
java·开发语言
jiaguangqingpanda20 小时前
Day22-20260118
java·开发语言
Ulyanov21 小时前
战场地形生成与多源数据集成
开发语言·python·算法·tkinter·pyside·pyvista·gui开发
风生u21 小时前
bpmn 的理解和元素
java·开发语言·工作流·bpmn
C+-C资深大佬21 小时前
C++数据类型
开发语言·c++·算法
ID_1800790547321 小时前
日本乐天商品详情API接口的请求构造与参数说明
开发语言·python·pandas
派大鑫wink21 小时前
【Day34】Servlet 进阶:会话管理(Cookie vs Session)
java·开发语言·学习方法
猫天意21 小时前
【深度学习小课堂】| torch | 升维打击还是原位拼接?深度解码 PyTorch 中 stack 与 cat 的几何奥义
开发语言·人工智能·pytorch·深度学习·神经网络·yolo·机器学习
crossaspeed1 天前
Java-线程池(八股)
java·开发语言
Voyager_41 天前
StringRedisTemplate 和 RedisTemplate 的区别是什么?
java·spring boot