We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Repeating Section Content Control example

Hello, I am looking into using the Repeating Section Content Control to populate a table in a Word 2016 docx document. After searching through the documentation and the Github I can’t see to find a good example of how to use the repeating content control with a set of data.

I would like to have a table with a row containing a set of content controls (i.e. Rich Text or Plain Text) with the row inside a repeating content control and then some how supply a set of data (datatable or xml) to populate the content controls and add more rows to reflect the number of rows in the data.

Is there any way this could be done?



Thanks for your inquiry. To ensure a timely and accurate response, please ZIP and attach the following resources here for testing:

  • Your simplified input Word document
  • XML data file
  • Aspose.Words generated output DOCX file showing the undesired behavior
  • Your expected DOCX Word document. We will investigate the structure of your expected document as to how you want your final output be generated like. You can create expected document by using Microsoft Word. Please also list the complete steps that you performed in MS Word to get the desired output
  • Please also create a standalone simple console application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing. Please do not include Aspose.Words.dll files in it to reduce the file size.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

It’s not that I’m having a problem with the Repeating Section Content Control, it’s that I don’t know how to use with Aspose.

I’m just looking for an example. Once I have that I’ll be in a better position to ask subsequent questions if they’re needed.


I think, you can meet this requirement by using the ‘Mail Merge with Regions’ feature of Aspose.Words. Please refer to the following sections of documentation.

How to Execute Mail Merge with Regions
How to Use Nested Mail Merge Regions

I would like to avoid using Mail Merge.

I just want to see an example of using the Repeating Section Content Control through Aspose.


We are checking this scenario and will get back to you soon.

A post was split to a new topic: Repeating section functionality


We have logged your requirement in our issue tracking system. Your ticket number is WORDSNET-17614. We will further look into the details of this requirement and will keep you updated on the status of the linked issue.


Regarding WORDSNET-17614, here is an example of how to bind the repeating section of the input document to XML:

Document doc = new Document("D:\\Temp\\Repeating Section Content Control.docx");

Table table = doc.FirstSection.Body.Tables[0];

StructuredDocumentTag repeatingSection = (StructuredDocumentTag)table.GetChild(NodeType.StructuredDocumentTag, 0, false);
Debug.Assert(repeatingSection != null && repeatingSection.SdtType == SdtType.RepeatingSection);
StructuredDocumentTag repeatingItem = (StructuredDocumentTag)repeatingSection.GetChild(NodeType.StructuredDocumentTag, 0, false);
Debug.Assert(repeatingItem != null);
StructuredDocumentTag[] repeatingSdts = (StructuredDocumentTag[])repeatingItem.GetChildNodes(NodeType.StructuredDocumentTag, true).ToArray();
Debug.Assert(repeatingSdts.Length == 4);

const string xml =
    @"<?xml version=""1.0"" encoding=""utf-8""?>
            <Name>John Doe</Name>
            <Name>Jane Adams</Name>
            <Name>John Smith</Name>

CustomXmlPart customXmlPart = doc.CustomXmlParts.Add(Guid.NewGuid().ToString("B"), xml);

repeatingSection.XmlMapping.SetMapping(customXmlPart, "/root/Employee", null);
repeatingSdts[0].XmlMapping.SetMapping(customXmlPart, "/root/Employee/Name", null);
repeatingSdts[1].XmlMapping.SetMapping(customXmlPart, "/root/Employee/HireDate", null);
repeatingSdts[2].XmlMapping.SetMapping(customXmlPart, "/root/Employee/Gender", null);
repeatingSdts[3].XmlMapping.SetMapping(customXmlPart, "/root/Employee/Department", null);


Example if input XML contains namespace declarations:

const string xml =
    @"<?xml version=""1.0"" encoding=""utf-8""?>
    <ns1:root xmlns:ns1='SomeNamespace'>
            <ns1:Name>John Doe</ns1:Name>
            <ns1:Name>Jane Adams</ns1:Name>
            <ns1:Name>John Smith</ns1:Name>
CustomXmlPart customXmlPart = doc.CustomXmlParts.Add(Guid.NewGuid().ToString("B"), xml);
const string namespaceMapping = "xmlns:ns0='SomeNamespace'";
repeatingSection.XmlMapping.SetMapping(customXmlPart, "/ns0:root/ns0:Employee", namespaceMapping);
repeatingSdts[0].XmlMapping.SetMapping(customXmlPart, "/ns0:root/ns0:Employee/ns0:Name", namespaceMapping);
repeatingSdts[1].XmlMapping.SetMapping(customXmlPart, "/ns0:root/ns0:Employee/ns0:HireDate", namespaceMapping);
repeatingSdts[2].XmlMapping.SetMapping(customXmlPart, "/ns0:root/ns0:Employee/ns0:Gender", namespaceMapping);
repeatingSdts[3].XmlMapping.SetMapping(customXmlPart, "/ns0:root/ns0:Employee/ns0:Department", namespaceMapping);
doc.Save(myDir + "Out2.docx");

Hope, this helps.


Regarding WORDSNET-17614, it is to update you that we have completed the analysis of this issue and come to a conclusion that we would not be able to implement the fix to this issue. Your issue (WORDSNET-17614) has now been closed with ‘Won’t Fix’ resolution. Please see my previous reply for details.