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++;
            }
        }

    }

表格模板如图:

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

相关推荐
雪雪爱冲浪10 分钟前
JavaScript 网络爬虫教程(2026)
开发语言·javascript·爬虫
ly768910 分钟前
PostgreSQL JSONB 在 Spring Boot 中的读写边界:从 JDBC 类型映射到 GIN 索引失效
spring boot·postgresql·gin·jsonb·pgjdbc·gin 索引
要吃这碗饭26 分钟前
JavaScript 网络爬虫教程(2026)
开发语言·javascript·爬虫
czq_268671948727 分钟前
Python打卡第40天
开发语言·python
yangmu320329 分钟前
Unity 开发过程与底层原理
java·开发语言
不爱吃鱼的蔓热莓30 分钟前
Autosar之根据ARXML中报文信息生成SWC(二)
开发语言·python
奈葵33 分钟前
Python语句
开发语言·python
紫洋葱hh43 分钟前
Go 入门基础:类型、变量与运算符
开发语言·后端·ai·golang
美味蛋炒饭.1 小时前
java八股面试(3)
java·开发语言·面试
言乐61 小时前
Python于LOLM针对伊泽瑞尔的数据分析
开发语言·python·机器学习·数据分析·pandas