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

    }

表格模板如图:

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

相关推荐
zh路西法2 分钟前
【C++委托与事件】函数指针,回调机制,事件式编程与松耦合的设计模式(上)
开发语言·c++·观察者模式·设计模式
闲猫9 分钟前
go 网络编程 websocket gorilla/websocket
开发语言·websocket·golang
m0_7482359526 分钟前
SpringBoot:解决前后端请求跨域问题(详细教程)
java·spring boot·后端
终极定律1 小时前
qt:输入控件操作
开发语言·qt
JenKinJia1 小时前
Windows10配置C++版本的Kafka,并进行发布和订阅测试
开发语言·c++
煤炭里de黑猫1 小时前
Lua C API :lua_insert 函数详解
开发语言·lua
笨鸟笃行1 小时前
爬虫第七篇数据爬取及解析
开发语言·爬虫·python
编程乐趣1 小时前
一文掌握DeepSeek本地部署+Page Assist浏览器插件+C#接口调用+局域网访问!全攻略来了!
开发语言·c#
java1234_小锋1 小时前
一周学会Flask3 Python Web开发-response响应格式
开发语言·python·flask·flask3
Jelena157795857921 小时前
使用Java爬虫获取1688 item_get_company 接口的公司档案信息
java·开发语言·爬虫