private byte[] SetContentInPlaceholders()
        {
            byte[] output;

            using (MemoryStream ms = new MemoryStream())
            {
                ms.Write(this.generationInfo.TemplateData, 0, this.generationInfo.TemplateData.Length);

                using (WordprocessingDocument wordDocument = WordprocessingDocument.Open(ms, true))
                {
                    wordDocument.ChangeDocumentType(WordprocessingDocumentType.Document);
                    MainDocumentPart mainDocumentPart = wordDocument.MainDocumentPart;
                    Document         document         = mainDocumentPart.Document;

                    // The sections that the user decided to remove from the build notes
                    foreach (var exclusion in this.exclusions)
                    {
                        var section =
                            document.Body.Descendants <SdtElement>().FirstOrDefault(
                                r => r.SdtProperties.GetFirstChild <Tag>().Val.HasValue&&
                                r.SdtProperties.GetFirstChild <Tag>().Val.Value ==
                                string.Format("{0}ContentControlRow", exclusion));
                        mainDocumentPart.Document.Body.RemoveChild(section);
                    }

                    if (this.generationInfo.Metadata != null)
                    {
                        this.SetDocumentProperties(mainDocumentPart, this.generationInfo.Metadata);
                    }

                    if (this.generationInfo.IsDataBoundControls)
                    {
                        this.SaveDataToDataBoundControlsDataStore(mainDocumentPart);
                    }

                    foreach (HeaderPart part in mainDocumentPart.HeaderParts)
                    {
                        this.SetContentInPlaceholders(new OpenXmlElementDataContext {
                            Element = part.Header, DataContext = this.generationInfo.DataContext
                        });
                        part.Header.Save();
                    }

                    foreach (FooterPart part in mainDocumentPart.FooterParts)
                    {
                        this.SetContentInPlaceholders(new OpenXmlElementDataContext {
                            Element = part.Footer, DataContext = this.generationInfo.DataContext
                        });
                        part.Footer.Save();
                    }

                    this.SetContentInPlaceholders(new OpenXmlElementDataContext {
                        Element = document, DataContext = this.generationInfo.DataContext
                    });

                    OpenXmlHelper.EnsureUniqueContentControlIdsForMainDocumentPart(mainDocumentPart);

                    document.Save();
                }

                ms.Position = 0;
                output      = new byte[ms.Length];
                ms.Read(output, 0, output.Length);
            }

            return(output);
        }