将原始模板文档部分中的子级复制到新文档部分的模板空位前后位置。当您的 for 循环到达模板位置时,添加新文本的第一行,复制模板位置,然后添加新文本的第二行。
for child = toModifyPart.Children
% If the child is a template holeif isa(child,"mlreportgen.dom.TemplateHole")
switch child.HoleId
case"templateHole"
append(newTemplateDocPart,...
Text("Text before template hole."));
append(newTemplateDocPart,TemplateHole(child.HoleId));
append(newTemplateDocPart,...
Text("Content after template hole"));
otherwise
append(newTemplateDocPart,TemplateHole(child.HoleId))
end% If the child is not the template hole, copy the child to % the new document partelse
append(newTemplateDocPart,clone(child));
endend