One pair of TableStart and TableEnd used in multi section document

Hello,
I want to know if is some solution to use only one pair of TableStart/TableEnd in MS Word document which contains more than one section ? In our company we have almost 100 Word templates and it will be difficult to change all to reflect this limitation.
Thanks for your answer,
Ondrej Slanina

Hi Ondrej,

Thanks for your inquiry.

Please note that the TableStart and TableEnd fields must be inside the same section in your document. If your Word document has multiple Sections, as a possible workaround you can programmatically insert multiple regions in each section and of-course Aspose.Words allows duplicate regions with same name (see MailMerge.MergeDuplicateRegions property). Here is sample code to insert regions in each section of document.

Document doc = new Document(MyDir + @"in.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
for (int i = 0; i < doc.Sections.Count; i++)
{
    builder.MoveToSection(i);
    FieldMergeField start = (FieldMergeField)builder.InsertField(FieldType.FieldMergeField, false);
    start.FieldName = "TableStart:tbl";
    builder.MoveTo(doc.Sections[i].Body.LastParagraph);
    FieldMergeField end = (FieldMergeField)builder.InsertField(FieldType.FieldMergeField, false);
    end.FieldName = "TableEnd:tbl";
}
doc.Save(MyDir + @"16.1.0.docx");

Hope, this helps.

Best regards,

Thank you, for your answer, i will test it…

Best regards,
Ondrej Slanina