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

    }

表格模板如图:

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

相关推荐
Yeats_Liao3 分钟前
Go语言技术与应用(二):分布式架构设计解析
开发语言·分布式·golang
脚踏实地的大梦想家8 分钟前
【Go】P6 Golang 基础:流程控制
开发语言·golang
信息快讯11 分钟前
“COMSOL+MATLAB光子学仿真:从入门到精通,掌握多物理场建模
开发语言·matlab·comsol·光学工程
LK_0713 分钟前
【Open3D】Ch.3:顶点法向量估计 | Python
开发语言·笔记·python
小码哥06822 分钟前
智能化招聘系统设计与实现-Java
开发语言·python
北山太湖24 分钟前
Matlab安装硬件支持包
开发语言·matlab
摇滚侠26 分钟前
Spring Boot 3零基础教程,yml配置文件,笔记13
spring boot·redis·笔记
-睡到自然醒~1 小时前
提升应用性能:Go中的同步与异步处理
开发语言·后端·golang
只吃不吃香菜1 小时前
Go WebSocket 协程泄漏问题分析与解决方案
开发语言·websocket·golang