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

    }

表格模板如图:

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

相关推荐
韩师学子--小倪12 分钟前
SpringBoot 优雅停服
spring boot·tomcat
Tansmjs19 分钟前
C++编译期数据结构
开发语言·c++·算法
金枪不摆鳍20 分钟前
算法-字典树
开发语言·算法
diediedei26 分钟前
C++类型推导(auto/decltype)
开发语言·c++·算法
索荣荣29 分钟前
Java动态代理实战:从原理到精通
java·开发语言
兩尛33 分钟前
c++的数组和Java数组的不同
java·开发语言·c++
roman_日积跬步-终至千里41 分钟前
【Java并发】多线程/并发问题集
java·开发语言
调皮连续波(rsp_tiaopige)1 小时前
毫米波雷达 : OpenRadar(Matlab版本)正式发布
开发语言·matlab
冷雨夜中漫步1 小时前
python反转列表reverse()和[::-1]哪个效率更高
开发语言·python
rainbow68891 小时前
Python面向对象编程与异常处理实战
开发语言·python