Dictionary<string, string> sequence = GetSequence(); using (WordprocessingDocument templateDocument = WordprocessingDocument.Open(sourceFileLocation, false)) { Body templateBody = templateDocument.MainDocumentPart.Document.Body; using ( WordprocessingDocument wordDoc = WordprocessingDocument.Create(destinationFileLocation, WordprocessingDocumentType.Document)) { MainDocumentPart mainPart = wordDoc.AddMainDocumentPart(); mainPart.Document = new Document(); Body wordDocDocBody = mainPart.Document.AppendChild(new Body()); //don't think the below two lines work as I intended. ThemePart themePart1 = templateDocument.MainDocumentPart.ThemePart; mainPart.AddPart(themePart1); foreach (var item in sequence) { var block = templateBody.Elements().TakeWhile(x => x.InnerText == item.Key); foreach (var blockItem in block) { wordDocBody.Append(blockItem.CloneNode(true)); } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)