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

    }

表格模板如图:

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

相关推荐
星辰_mya5 分钟前
CountDownLatch深度解析
java·开发语言·后端·架构
laplaya9 分钟前
使用 vcpkg 管理 C++ 项目中的依赖
开发语言·c++
feixing_fx20 分钟前
选择器的威力——深入理解优先级计算与层叠规则
开发语言·前端·css·前端框架·html
6v6-博客28 分钟前
C语言字符串中空格的表示方法
c语言·开发语言
geovindu30 分钟前
python: speech to text offline
开发语言·python·语音识别
于指尖飞舞41 分钟前
java后端面试题(多线程极简)
java·开发语言
techdashen43 分钟前
从 Windows 的 ping.exe 入手:动态库、调用约定与 Rust FFI
开发语言·windows·rust
AI科技星1 小时前
数术宇宙:零一无穷创世史诗
开发语言·网络·量子计算·拓扑学
是多巴胺不是尼古丁2 小时前
期末java复习--string
java·开发语言·python
Survivor0012 小时前
高并发系统流量治理的底层算法
java·开发语言