Create Table Repeating Section Content Control in Word Document - C# .NET Code Example

Hi,
i was looking for an example of using repeating section content control and i have found Repeating section functionality
but the zip file containing the “Repeating Section Content Control.docx” is not available.

Could you sent it to me in order to be able to use the sample ?

thanks in advance.

@tparassin

Please get the requested file from attachment. Repeating Section Content Control.zip (30.7 KB)

thank you for your quick reply

@tparassin

Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.

@tparassin,

It is to update you that starting from the 19.9 versions, you can use Aspose.Words for .NET and Aspose.Words for Java APIs to create Structured Document Tag nodes (Content Controls) of the Repeating Section and Repeating Section Item types. The new items have also been added into the SdtType enumeration.

You can use the following C# code example to create a Table Repeating Section and map it to a custom XML part:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

CustomXmlPart xmlPart = doc.CustomXmlParts.Add("Books",
"<books><book><title>Everyday Italian</title><author>Giada De Laurentiis</author></book>" +
"<book><title>Harry Potter</title><author>J K. Rowling</author></book>" +
"<book><title>Learning XML</title><author>Erik T. Ray</author></book></books>");

Table table = builder.StartTable();

builder.InsertCell();
builder.Write("Title");

builder.InsertCell();
builder.Write("Author");

builder.EndRow();
builder.EndTable();

StructuredDocumentTag repeatingSectionSdt =
new StructuredDocumentTag(doc, SdtType.RepeatingSection, MarkupLevel.Row);
repeatingSectionSdt.XmlMapping.SetMapping(xmlPart, "/books[1]/book", "");
table.AppendChild(repeatingSectionSdt);

StructuredDocumentTag repeatingSectionItemSdt =
new StructuredDocumentTag(doc, SdtType.RepeatingSectionItem, MarkupLevel.Row);
repeatingSectionSdt.AppendChild(repeatingSectionItemSdt);

Row row = new Row(doc);
repeatingSectionItemSdt.AppendChild(row);

StructuredDocumentTag titleSdt =
new StructuredDocumentTag(doc, SdtType.PlainText, MarkupLevel.Cell);
titleSdt.XmlMapping.SetMapping(xmlPart, "/books[1]/book[1]/title[1]", "");
row.AppendChild(titleSdt);

StructuredDocumentTag authorSdt =
new StructuredDocumentTag(doc, SdtType.PlainText, MarkupLevel.Cell);
authorSdt.XmlMapping.SetMapping(xmlPart, "/books[1]/book[1]/author[1]", "");
row.AppendChild(authorSdt);

doc.Save("E:\\Temp\\Table Repeating Section mapped to a custom XML part.docx");