public void Load(string collectionTagName, IEnumerable <object> data, string name = null) { var collectionData = new List <WordTemplateData>(); foreach (var o in data) { var templateData = new WordTemplateData(); templateData.Load(o, name); collectionData.Add(templateData); } Add(new CollectionData { TagName = collectionTagName, ElementData = collectionData }); }
public static MemoryStream Generate(WordTemplateData data, Stream template, Stream existingDocument = null) { var output = new MemoryStream(); if (existingDocument != null) { existingDocument.CopyTo(output); } else { template.CopyTo(output); } using (var templateDocument = WordprocessingDocument.Open(template, true)) using (var wordDocument = WordprocessingDocument.Open(output, true)) { data.Template = templateDocument.MainDocumentPart.RootElement.Descendants <SdtElement>(); data.Apply(wordDocument); } return(output); }