Add text fields to your document: DEVELOPER -> Controls -> Rich Text Content Control. Set control's tag value to name you will use later.
- Create 'DocxGenerator':
var docx = new DocxGenerator(@"C:\Temp\MyTestTemplates\Hello Tag 1.docx");
- Create 'Leaflet':
Leaflet leaflet = new Leaflet();
docx.AddLeaflet(leaflet);
- Fill tags:
leaflet.AddGlobal("tag name", "value");
- Save document:
docx.Generate(@"C:\Temp\MyTestTemplates\outFile");
Do the same as for single leaflet, but create and add Leaflet several times. Example:
var docx = new DocxGenerator(@"C:\Temp\MyTestTemplates\Hello Tag 1.docx");
foreach (var leafletData in <>)
{
Leaflet leaflet = new Leaflet();
leaflet.AddGlobal("Tag 1", "Henny");
docx.AddLeaflet(leaflet);
}
docx.Generate(@"C:\Temp\MyTestTemplates\outFile");
- Add table, add same tags to it.
- Select line you are going to repeat for registry.
- With line selected, click: DEVELOPER -> Controls -> Repeating Section Content Control.
- Set tag value, for example 'MyList'.
- Create 'DocxGenerator':
var docx = new DocxGenerator(@"C:\Temp\MyTestTemplates\Hello Tag 1.docx");
- Create 'Leaflet':
Leaflet leaflet = new Leaflet();
docx.AddLeaflet(leaflet);
- Fill tags for whole document:
leaflet.AddGlobal("tag name", "value");
- Add row, where it is tagged as 'MyList':
leaflet.AddLine("MyList",
new KeyValuePair("Item1", (i + 1).ToString()),
new KeyValuePair("Item2", "Value 2"),
new KeyValuePair("Item3", "Value 3"),
new KeyValuePair("Item4", "Hello Registry!")
);
- Save document:
docx.Generate(@"C:\Temp\MyTestTemplates\outFile");