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

    }

表格模板如图:

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

相关推荐
长河34 分钟前
Java开发者LLM实战——LangChain4j最新版教学知识库实战
java·开发语言
Cyan_RA944 分钟前
SpringMVC @RequestMapping的使用演示和细节 详解
java·开发语言·后端·spring·mvc·ssm·springmvc
再见晴天*_*4 小时前
SpringBoot 中单独一个类中运行main方法报错:找不到或无法加载主类
java·开发语言·intellij idea
lqjun08275 小时前
Qt程序单独运行报错问题
开发语言·qt
hdsoft_huge7 小时前
Java & Spring Boot常见异常全解析:原因、危害、处理与防范
java·开发语言·spring boot
风中的微尘7 小时前
39.网络流入门
开发语言·网络·c++·算法
未来之窗软件服务8 小时前
幽冥大陆(二)RDIFSDK 接口文档:布草洗涤厂高效运营的技术桥梁C#—东方仙盟
开发语言·c#·rdif·仙盟创梦ide·东方仙盟
小冯记录编程8 小时前
C++指针陷阱:高效背后的致命危险
开发语言·c++·visual studio
1uther8 小时前
Unity核心概念⑨:Screen
开发语言·游戏·unity·c#·游戏引擎
C_Liu_9 小时前
C++:类和对象(下)
开发语言·c++