using System.IO;
using TemplateEngine.Docx;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
File.Delete("OutputDocument.docx");
File.Copy("InputTemplate.docx", "OutputDocument.docx");
var valuesToFill = new Content(
new RepeatContent("RepeatParentContent")
.AddItem(
new RepeatContent("RepeatChildrenContent").Hide()
.AddItem(new FieldContent("OrganizationName", "Рога и копыта")))
);
using (var outputDocument = new TemplateProcessor("OutputDocument.docx")
.SetRemoveContentControls(true))
{
outputDocument.FillContent(valuesToFill);
outputDocument.SaveChanges();
}
}
}
}
Exception locate is file RepeatProcessor.cs, line 105 (code:
contentControl.DescendantsAndSelf(W.sdt).Remove();)
Error message: The parent is missing
Input file: InputTemplate.docx
Programm code: