예제 #1
0
        public DCTDataColumnCollection(TableRow titleRow)
        {
            coveredControlIds = new List <int>();

            var cells = titleRow.Descendants <TableCell>().ToList();

            //针对每一个区域,先读取表头的控件,同时将控件加入黑名单
            for (int i = 0; i < cells.Count; i++)
            {
                var sdtElement = cells[i].Descendants <SdtElement>().Where(o => o.SdtProperties.Descendants <SdtAlias>().Any(a => a.Val != null)).FirstOrDefault();
                if (null == sdtElement)
                {
                    continue;
                }
                SdtAlias titleAlias = sdtElement.Descendants <SdtAlias>().FirstOrDefault();
                SdtId    titleId    = sdtElement.Descendants <SdtId>().FirstOrDefault();
                if (null == titleAlias)
                {
                    continue;
                }
                this[i] = new DCTDataColumn(titleAlias.Val);
                //properties.Add(alias);
                CoveredControlIds.Add(titleId.Val.Value);
            }
        }
예제 #2
0
 public static void replacePicture(string filePath)
 {
     using (WordprocessingDocument doc =
                WordprocessingDocument.Open(filePath, true))
     {
         SdtBlock cc = doc.MainDocumentPart.Document.Body.Descendants <SdtBlock>()
                       .FirstOrDefault(c =>
         {
             SdtProperties p = c.Elements <SdtProperties>().FirstOrDefault();
             if (p != null)
             {
                 // Is it a picture content control?
                 SdtContentPicture pict =
                     p.Elements <SdtContentPicture>().FirstOrDefault();
                 // Get the alias.
                 SdtAlias a = p.Elements <SdtAlias>().FirstOrDefault();
                 if (pict != null)
                 {
                     return(true);
                 }
             }
             return(false);
         });
         string embed = null;
         if (cc != null)
         {
             Drawing dr = cc.Descendants <Drawing>().FirstOrDefault();
             if (dr != null)
             {
                 Blip blip = dr.Descendants <Blip>().FirstOrDefault();
                 if (blip != null)
                 {
                     embed = blip.Embed;
                 }
             }
         }
         if (embed != null)
         {
             IdPartPair idpp = doc.MainDocumentPart.Parts
                               .Where(pa => pa.RelationshipId == embed).FirstOrDefault();
             if (idpp != null)
             {
                 ImagePart ip = (ImagePart)idpp.OpenXmlPart;
                 using (FileStream fileStream =
                            File.Open("test.png", FileMode.Open))
                     ip.FeedData(fileStream);
             }
         }
     }
 }
        private JObject ProcessStdProperties(OpenXmlElement element)
        {
            var result = new JObject();

            foreach (var prop in element.ChildElements)
            {
                if (prop.LocalName == "alias")
                {
                    SdtAlias sdtAlias = (SdtAlias)prop;
                    result.Add("alias", sdtAlias.Val.ToString());
                }
                else if (prop.LocalName == "tag")
                {
                    Tag t = (Tag)prop;
                    result.Add("tag", t.Val.ToString());
                }
            }

            return(result);
        }
예제 #4
0
        private WordTemplateModel GenerateDataMappingOxml(string TemplateFileLocation, WordTemplateModel model)
        {
            try
            {
                using (WordprocessingDocument document = WordprocessingDocument.Open(TemplateFileLocation, true))
                {
                    // Change the document type to Document
                    document.ChangeDocumentType(DocumentFormat.OpenXml.WordprocessingDocumentType.Document);

                    // Get the MainPart of the document
                    MainDocumentPart mainPart = document.MainDocumentPart;

                    // Get the Document Settings Part
                    DocumentSettingsPart documentSettingPart1 = mainPart.DocumentSettingsPart;
                    OpenXmlElement[]     Enumerate            = mainPart.ContentControls().ToArray();
                    List <ModelField>    dataMapping          = new List <ModelField>();
                    for (int i = 0; i < Enumerate.Count(); i++)
                    {
                        OpenXmlElement cc      = Enumerate[i];
                        SdtProperties  props   = cc.Elements <SdtProperties>().FirstOrDefault();
                        Tag            tag     = props.Elements <Tag>().FirstOrDefault();
                        SdtAlias       alias   = props.Elements <SdtAlias>().FirstOrDefault();
                        string         title   = ((DocumentFormat.OpenXml.Wordprocessing.StringType)(alias)).Val;
                        string         tagName = tag.Val;

                        dataMapping.Add(new ModelField()
                        {
                            Key = title
                        });
                    }

                    model.DataMapping = dataMapping;
                }
            }
            catch (Exception ex)
            {
                throw;
            }

            return(model);
        }
예제 #5
0
        // Generates content of mainDocumentPart1.
        private void GenerateMainDocumentPart1Content(MainDocumentPart mainDocumentPart1)
        {
            Document document1 = new Document(){ MCAttributes = new MarkupCompatibilityAttributes(){ Ignorable = "w14 w15 wp14" }  };
            document1.AddNamespaceDeclaration("wpc", "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas");
            document1.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006");
            document1.AddNamespaceDeclaration("o", "urn:schemas-microsoft-com:office:office");
            document1.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
            document1.AddNamespaceDeclaration("m", "http://schemas.openxmlformats.org/officeDocument/2006/math");
            document1.AddNamespaceDeclaration("v", "urn:schemas-microsoft-com:vml");
            document1.AddNamespaceDeclaration("wp14", "http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing");
            document1.AddNamespaceDeclaration("wp", "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing");
            document1.AddNamespaceDeclaration("w10", "urn:schemas-microsoft-com:office:word");
            document1.AddNamespaceDeclaration("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main");
            document1.AddNamespaceDeclaration("w14", "http://schemas.microsoft.com/office/word/2010/wordml");
            document1.AddNamespaceDeclaration("w15", "http://schemas.microsoft.com/office/word/2010/11/wordml");
            document1.AddNamespaceDeclaration("wpg", "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup");
            document1.AddNamespaceDeclaration("wpi", "http://schemas.microsoft.com/office/word/2010/wordprocessingInk");
            document1.AddNamespaceDeclaration("wne", "http://schemas.microsoft.com/office/word/2006/wordml");
            document1.AddNamespaceDeclaration("wps", "http://schemas.microsoft.com/office/word/2010/wordprocessingShape");

            Body body1 = new Body();

            SdtBlock sdtBlock1 = new SdtBlock();

            SdtProperties sdtProperties1 = new SdtProperties();

            RunProperties runProperties1 = new RunProperties();
            RunFonts runFonts1 = new RunFonts(){ Hint = FontTypeHintValues.EastAsia };

            runProperties1.Append(runFonts1);
            SdtAlias sdtAlias1 = new SdtAlias(){ Val = "Test1.1.1" };
            Tag tag1 = new Tag(){ Val = "Test1.1.1" };
            SdtId sdtId1 = new SdtId(){ Val = -1832063964 };

            SdtPlaceholder sdtPlaceholder1 = new SdtPlaceholder();
            DocPartReference docPartReference1 = new DocPartReference(){ Val = "DefaultPlaceholder_1081868558" };

            sdtPlaceholder1.Append(docPartReference1);
            ShowingPlaceholder showingPlaceholder1 = new ShowingPlaceholder();
            SdtContentText sdtContentText1 = new SdtContentText();

            sdtProperties1.Append(runProperties1);
            sdtProperties1.Append(sdtAlias1);
            sdtProperties1.Append(tag1);
            sdtProperties1.Append(sdtId1);
            sdtProperties1.Append(sdtPlaceholder1);
            sdtProperties1.Append(showingPlaceholder1);
            sdtProperties1.Append(sdtContentText1);
            SdtEndCharProperties sdtEndCharProperties1 = new SdtEndCharProperties();

            SdtContentBlock sdtContentBlock1 = new SdtContentBlock();

            Paragraph paragraph1 = new Paragraph(){ RsidParagraphAddition = "00535C5E", RsidRunAdditionDefault = "000010BA" };

            Run run1 = new Run(){ RsidRunProperties = "003E0DED" };

            RunProperties runProperties2 = new RunProperties();
            RunStyle runStyle1 = new RunStyle(){ Val = "PlaceholderText" };

            runProperties2.Append(runStyle1);
            Text text1 = new Text();
            text1.Text = "Click here to enter text.";

            run1.Append(runProperties2);
            run1.Append(text1);

            paragraph1.Append(run1);

            sdtContentBlock1.Append(paragraph1);

            sdtBlock1.Append(sdtProperties1);
            sdtBlock1.Append(sdtEndCharProperties1);
            sdtBlock1.Append(sdtContentBlock1);

            SdtBlock sdtBlock2 = new SdtBlock();

            SdtProperties sdtProperties2 = new SdtProperties();

            RunProperties runProperties3 = new RunProperties();
            RunFonts runFonts2 = new RunFonts(){ Hint = FontTypeHintValues.EastAsia };

            runProperties3.Append(runFonts2);
            SdtAlias sdtAlias2 = new SdtAlias(){ Val = "Test1.1.2" };
            Tag tag2 = new Tag(){ Val = "Test1.1.2" };
            SdtId sdtId2 = new SdtId(){ Val = -2043657734 };

            SdtPlaceholder sdtPlaceholder2 = new SdtPlaceholder();
            DocPartReference docPartReference2 = new DocPartReference(){ Val = "DefaultPlaceholder_1081868558" };

            sdtPlaceholder2.Append(docPartReference2);
            SdtContentText sdtContentText2 = new SdtContentText();

            sdtProperties2.Append(runProperties3);
            sdtProperties2.Append(sdtAlias2);
            sdtProperties2.Append(tag2);
            sdtProperties2.Append(sdtId2);
            sdtProperties2.Append(sdtPlaceholder2);
            sdtProperties2.Append(sdtContentText2);
            SdtEndCharProperties sdtEndCharProperties2 = new SdtEndCharProperties();

            SdtContentBlock sdtContentBlock2 = new SdtContentBlock();

            Paragraph paragraph2 = new Paragraph(){ RsidParagraphAddition = "000010BA", RsidRunAdditionDefault = "000010BA" };

            Run run2 = new Run();

            RunProperties runProperties4 = new RunProperties();
            RunFonts runFonts3 = new RunFonts(){ Hint = FontTypeHintValues.EastAsia };

            runProperties4.Append(runFonts3);
            Text text2 = new Text();
            text2.Text = "Test string";

            run2.Append(runProperties4);
            run2.Append(text2);

            paragraph2.Append(run2);

            sdtContentBlock2.Append(paragraph2);

            sdtBlock2.Append(sdtProperties2);
            sdtBlock2.Append(sdtEndCharProperties2);
            sdtBlock2.Append(sdtContentBlock2);

            SdtBlock sdtBlock3 = new SdtBlock();

            SdtProperties sdtProperties3 = new SdtProperties();

            RunProperties runProperties5 = new RunProperties();
            RunFonts runFonts4 = new RunFonts(){ Hint = FontTypeHintValues.EastAsia };

            runProperties5.Append(runFonts4);
            SdtAlias sdtAlias3 = new SdtAlias(){ Val = "Test1.2.1" };
            Tag tag3 = new Tag(){ Val = "Test1.2.1" };
            SdtId sdtId3 = new SdtId(){ Val = 401180698 };

            SdtPlaceholder sdtPlaceholder3 = new SdtPlaceholder();
            DocPartReference docPartReference3 = new DocPartReference(){ Val = "DefaultPlaceholder_1081868558" };

            sdtPlaceholder3.Append(docPartReference3);
            SdtContentText sdtContentText3 = new SdtContentText();

            sdtProperties3.Append(runProperties5);
            sdtProperties3.Append(sdtAlias3);
            sdtProperties3.Append(tag3);
            sdtProperties3.Append(sdtId3);
            sdtProperties3.Append(sdtPlaceholder3);
            sdtProperties3.Append(sdtContentText3);
            SdtEndCharProperties sdtEndCharProperties3 = new SdtEndCharProperties();

            SdtContentBlock sdtContentBlock3 = new SdtContentBlock();

            Paragraph paragraph3 = new Paragraph(){ RsidParagraphAddition = "000010BA", RsidRunAdditionDefault = "000010BA" };

            Run run3 = new Run();

            RunProperties runProperties6 = new RunProperties();
            RunFonts runFonts5 = new RunFonts(){ Hint = FontTypeHintValues.EastAsia };

            runProperties6.Append(runFonts5);
            Text text3 = new Text();
            text3.Text = "Appearance1";

            run3.Append(runProperties6);
            run3.Append(text3);

            paragraph3.Append(run3);

            sdtContentBlock3.Append(paragraph3);

            sdtBlock3.Append(sdtProperties3);
            sdtBlock3.Append(sdtEndCharProperties3);
            sdtBlock3.Append(sdtContentBlock3);

            SdtBlock sdtBlock4 = new SdtBlock();

            SdtProperties sdtProperties4 = new SdtProperties();

            RunProperties runProperties7 = new RunProperties();
            RunFonts runFonts6 = new RunFonts(){ Hint = FontTypeHintValues.EastAsia };

            runProperties7.Append(runFonts6);
            SdtAlias sdtAlias4 = new SdtAlias(){ Val = "Test1.2.2" };
            Tag tag4 = new Tag(){ Val = "Test1.2.2" };
            SdtId sdtId4 = new SdtId(){ Val = 2096980748 };

            SdtPlaceholder sdtPlaceholder4 = new SdtPlaceholder();
            DocPartReference docPartReference4 = new DocPartReference(){ Val = "DefaultPlaceholder_1081868558" };

            sdtPlaceholder4.Append(docPartReference4);
            W15.Appearance appearance1 = new W15.Appearance(){ Val = W15.SdtAppearance.Tags };
            SdtContentText sdtContentText4 = new SdtContentText();

            sdtProperties4.Append(runProperties7);
            sdtProperties4.Append(sdtAlias4);
            sdtProperties4.Append(tag4);
            sdtProperties4.Append(sdtId4);
            sdtProperties4.Append(sdtPlaceholder4);
            sdtProperties4.Append(appearance1);
            sdtProperties4.Append(sdtContentText4);
            SdtEndCharProperties sdtEndCharProperties4 = new SdtEndCharProperties();

            SdtContentBlock sdtContentBlock4 = new SdtContentBlock();

            Paragraph paragraph4 = new Paragraph(){ RsidParagraphAddition = "000010BA", RsidRunAdditionDefault = "000010BA" };

            Run run4 = new Run();

            RunProperties runProperties8 = new RunProperties();
            RunFonts runFonts7 = new RunFonts(){ Hint = FontTypeHintValues.EastAsia };

            runProperties8.Append(runFonts7);
            Text text4 = new Text();
            text4.Text = "Appearance2";

            run4.Append(runProperties8);
            run4.Append(text4);

            paragraph4.Append(run4);

            sdtContentBlock4.Append(paragraph4);

            sdtBlock4.Append(sdtProperties4);
            sdtBlock4.Append(sdtEndCharProperties4);
            sdtBlock4.Append(sdtContentBlock4);

            SdtBlock sdtBlock5 = new SdtBlock();

            SdtProperties sdtProperties5 = new SdtProperties();

            RunProperties runProperties9 = new RunProperties();
            RunFonts runFonts8 = new RunFonts(){ Hint = FontTypeHintValues.EastAsia };

            runProperties9.Append(runFonts8);
            SdtAlias sdtAlias5 = new SdtAlias(){ Val = "Test1.2.3" };
            Tag tag5 = new Tag(){ Val = "Test1.2.3" };
            SdtId sdtId5 = new SdtId(){ Val = -343394056 };

            SdtPlaceholder sdtPlaceholder5 = new SdtPlaceholder();
            DocPartReference docPartReference5 = new DocPartReference(){ Val = "DefaultPlaceholder_1081868558" };

            sdtPlaceholder5.Append(docPartReference5);
            W15.Appearance appearance2 = new W15.Appearance(){ Val = W15.SdtAppearance.Hidden };
            SdtContentText sdtContentText5 = new SdtContentText();

            sdtProperties5.Append(runProperties9);
            sdtProperties5.Append(sdtAlias5);
            sdtProperties5.Append(tag5);
            sdtProperties5.Append(sdtId5);
            sdtProperties5.Append(sdtPlaceholder5);
            sdtProperties5.Append(appearance2);
            sdtProperties5.Append(sdtContentText5);
            SdtEndCharProperties sdtEndCharProperties5 = new SdtEndCharProperties();

            SdtContentBlock sdtContentBlock5 = new SdtContentBlock();

            Paragraph paragraph5 = new Paragraph(){ RsidParagraphAddition = "000010BA", RsidRunAdditionDefault = "000010BA" };

            Run run5 = new Run();

            RunProperties runProperties10 = new RunProperties();
            RunFonts runFonts9 = new RunFonts(){ Hint = FontTypeHintValues.EastAsia };

            runProperties10.Append(runFonts9);
            Text text5 = new Text();
            text5.Text = "Appearance3";

            run5.Append(runProperties10);
            run5.Append(text5);

            paragraph5.Append(run5);

            sdtContentBlock5.Append(paragraph5);

            sdtBlock5.Append(sdtProperties5);
            sdtBlock5.Append(sdtEndCharProperties5);
            sdtBlock5.Append(sdtContentBlock5);

            SdtBlock sdtBlock6 = new SdtBlock();

            SdtProperties sdtProperties6 = new SdtProperties();

            RunProperties runProperties11 = new RunProperties();
            RunFonts runFonts10 = new RunFonts(){ Hint = FontTypeHintValues.EastAsia };

            runProperties11.Append(runFonts10);
            SdtAlias sdtAlias6 = new SdtAlias(){ Val = "Test1.3.1" };
            Tag tag6 = new Tag(){ Val = "Test1.3.1" };
            SdtId sdtId6 = new SdtId(){ Val = 1119424041 };

            SdtPlaceholder sdtPlaceholder6 = new SdtPlaceholder();
            DocPartReference docPartReference6 = new DocPartReference(){ Val = "DefaultPlaceholder_1081868558" };

            sdtPlaceholder6.Append(docPartReference6);
            SdtContentText sdtContentText6 = new SdtContentText();

            sdtProperties6.Append(runProperties11);
            sdtProperties6.Append(sdtAlias6);
            sdtProperties6.Append(tag6);
            sdtProperties6.Append(sdtId6);
            sdtProperties6.Append(sdtPlaceholder6);
            sdtProperties6.Append(sdtContentText6);
            SdtEndCharProperties sdtEndCharProperties6 = new SdtEndCharProperties();

            SdtContentBlock sdtContentBlock6 = new SdtContentBlock();

            Paragraph paragraph6 = new Paragraph(){ RsidParagraphAddition = "000010BA", RsidRunAdditionDefault = "000010BA" };

            Run run6 = new Run();

            RunProperties runProperties12 = new RunProperties();
            RunFonts runFonts11 = new RunFonts(){ Hint = FontTypeHintValues.EastAsia };

            runProperties12.Append(runFonts11);
            Text text6 = new Text();
            text6.Text = "Color Content Control1";

            run6.Append(runProperties12);
            run6.Append(text6);

            paragraph6.Append(run6);

            sdtContentBlock6.Append(paragraph6);

            sdtBlock6.Append(sdtProperties6);
            sdtBlock6.Append(sdtEndCharProperties6);
            sdtBlock6.Append(sdtContentBlock6);

            SdtBlock sdtBlock7 = new SdtBlock();

            SdtProperties sdtProperties7 = new SdtProperties();

            RunProperties runProperties13 = new RunProperties();
            RunFonts runFonts12 = new RunFonts(){ Hint = FontTypeHintValues.EastAsia };

            runProperties13.Append(runFonts12);
            SdtAlias sdtAlias7 = new SdtAlias(){ Val = "Test1.3.2" };
            Tag tag7 = new Tag(){ Val = "Test1.3.2" };
            SdtId sdtId7 = new SdtId(){ Val = 550972260 };

            SdtPlaceholder sdtPlaceholder7 = new SdtPlaceholder();
            DocPartReference docPartReference7 = new DocPartReference(){ Val = "DefaultPlaceholder_1081868558" };

            sdtPlaceholder7.Append(docPartReference7);
            W15.Color color1 = new W15.Color(){ Val = "0000FF" };
            SdtContentText sdtContentText7 = new SdtContentText();

            sdtProperties7.Append(runProperties13);
            sdtProperties7.Append(sdtAlias7);
            sdtProperties7.Append(tag7);
            sdtProperties7.Append(sdtId7);
            sdtProperties7.Append(sdtPlaceholder7);
            sdtProperties7.Append(color1);
            sdtProperties7.Append(sdtContentText7);
            SdtEndCharProperties sdtEndCharProperties7 = new SdtEndCharProperties();

            SdtContentBlock sdtContentBlock7 = new SdtContentBlock();

            Paragraph paragraph7 = new Paragraph(){ RsidParagraphAddition = "000010BA", RsidRunAdditionDefault = "000010BA" };

            Run run7 = new Run();

            RunProperties runProperties14 = new RunProperties();
            RunFonts runFonts13 = new RunFonts(){ Hint = FontTypeHintValues.EastAsia };

            runProperties14.Append(runFonts13);
            Text text7 = new Text();
            text7.Text = "Color Content Control2";

            run7.Append(runProperties14);
            run7.Append(text7);

            paragraph7.Append(run7);

            sdtContentBlock7.Append(paragraph7);

            sdtBlock7.Append(sdtProperties7);
            sdtBlock7.Append(sdtEndCharProperties7);
            sdtBlock7.Append(sdtContentBlock7);

            SdtBlock sdtBlock8 = new SdtBlock();

            SdtProperties sdtProperties8 = new SdtProperties();

            RunProperties runProperties15 = new RunProperties();
            RunFonts runFonts14 = new RunFonts(){ Hint = FontTypeHintValues.EastAsia };

            runProperties15.Append(runFonts14);
            SdtAlias sdtAlias8 = new SdtAlias(){ Val = "Test1.4.1" };
            Tag tag8 = new Tag(){ Val = "Test1.4.1" };
            SdtId sdtId8 = new SdtId(){ Val = 1758249604 };
            W15.SdtRepeatedSection sdtRepeatedSection1 = new W15.SdtRepeatedSection();

            sdtProperties8.Append(runProperties15);
            sdtProperties8.Append(sdtAlias8);
            sdtProperties8.Append(tag8);
            sdtProperties8.Append(sdtId8);
            sdtProperties8.Append(sdtRepeatedSection1);
            SdtEndCharProperties sdtEndCharProperties8 = new SdtEndCharProperties();

            SdtContentBlock sdtContentBlock8 = new SdtContentBlock();

            SdtBlock sdtBlock9 = new SdtBlock();

            SdtProperties sdtProperties9 = new SdtProperties();

            RunProperties runProperties16 = new RunProperties();
            RunFonts runFonts15 = new RunFonts(){ Hint = FontTypeHintValues.EastAsia };

            runProperties16.Append(runFonts15);
            SdtId sdtId9 = new SdtId(){ Val = 481433089 };

            SdtPlaceholder sdtPlaceholder8 = new SdtPlaceholder();
            DocPartReference docPartReference8 = new DocPartReference(){ Val = "DefaultPlaceholder_1081868562" };

            sdtPlaceholder8.Append(docPartReference8);
            ShowingPlaceholder showingPlaceholder2 = new ShowingPlaceholder();
            W15.SdtRepeatedSectionItem sdtRepeatedSectionItem1 = new W15.SdtRepeatedSectionItem();

            sdtProperties9.Append(runProperties16);
            sdtProperties9.Append(sdtId9);
            sdtProperties9.Append(sdtPlaceholder8);
            sdtProperties9.Append(showingPlaceholder2);
            sdtProperties9.Append(sdtRepeatedSectionItem1);
            SdtEndCharProperties sdtEndCharProperties9 = new SdtEndCharProperties();

            SdtContentBlock sdtContentBlock9 = new SdtContentBlock();

            Paragraph paragraph8 = new Paragraph(){ RsidParagraphAddition = "000010BA", RsidRunAdditionDefault = "000010BA" };

            Run run8 = new Run(){ RsidRunProperties = "003E0DED" };

            RunProperties runProperties17 = new RunProperties();
            RunStyle runStyle2 = new RunStyle(){ Val = "PlaceholderText" };

            runProperties17.Append(runStyle2);
            Text text8 = new Text();
            text8.Text = "Enter any content that you want to repeat, including other content controls. You can also insert this control around table rows in order to repeat parts of a table.";

            run8.Append(runProperties17);
            run8.Append(text8);

            paragraph8.Append(run8);

            sdtContentBlock9.Append(paragraph8);

            sdtBlock9.Append(sdtProperties9);
            sdtBlock9.Append(sdtEndCharProperties9);
            sdtBlock9.Append(sdtContentBlock9);

            sdtContentBlock8.Append(sdtBlock9);

            sdtBlock8.Append(sdtProperties8);
            sdtBlock8.Append(sdtEndCharProperties8);
            sdtBlock8.Append(sdtContentBlock8);

            SdtBlock sdtBlock10 = new SdtBlock();

            SdtProperties sdtProperties10 = new SdtProperties();

            RunProperties runProperties18 = new RunProperties();
            RunFonts runFonts16 = new RunFonts(){ Hint = FontTypeHintValues.EastAsia };

            runProperties18.Append(runFonts16);
            SdtAlias sdtAlias9 = new SdtAlias(){ Val = "Test1.4.2" };
            Tag tag9 = new Tag(){ Val = "Test1.4.2" };
            SdtId sdtId10 = new SdtId(){ Val = -78606169 };
            W15.SdtRepeatedSection sdtRepeatedSection2 = new W15.SdtRepeatedSection();

            sdtProperties10.Append(runProperties18);
            sdtProperties10.Append(sdtAlias9);
            sdtProperties10.Append(tag9);
            sdtProperties10.Append(sdtId10);
            sdtProperties10.Append(sdtRepeatedSection2);
            SdtEndCharProperties sdtEndCharProperties10 = new SdtEndCharProperties();

            SdtContentBlock sdtContentBlock10 = new SdtContentBlock();

            SdtBlock sdtBlock11 = new SdtBlock();

            SdtProperties sdtProperties11 = new SdtProperties();

            RunProperties runProperties19 = new RunProperties();
            RunFonts runFonts17 = new RunFonts(){ Hint = FontTypeHintValues.EastAsia };

            runProperties19.Append(runFonts17);
            SdtId sdtId11 = new SdtId(){ Val = -1356270719 };

            SdtPlaceholder sdtPlaceholder9 = new SdtPlaceholder();
            DocPartReference docPartReference9 = new DocPartReference(){ Val = "DefaultPlaceholder_1081868562" };

            sdtPlaceholder9.Append(docPartReference9);
            W15.SdtRepeatedSectionItem sdtRepeatedSectionItem2 = new W15.SdtRepeatedSectionItem();

            sdtProperties11.Append(runProperties19);
            sdtProperties11.Append(sdtId11);
            sdtProperties11.Append(sdtPlaceholder9);
            sdtProperties11.Append(sdtRepeatedSectionItem2);
            SdtEndCharProperties sdtEndCharProperties11 = new SdtEndCharProperties();

            SdtContentBlock sdtContentBlock11 = new SdtContentBlock();

            Paragraph paragraph9 = new Paragraph(){ RsidParagraphAddition = "000010BA", RsidRunAdditionDefault = "000010BA" };
            ProofError proofError1 = new ProofError(){ Type = ProofingErrorValues.SpellStart };
            ProofError proofError2 = new ProofError(){ Type = ProofingErrorValues.GrammarStart };

            Run run9 = new Run();

            RunProperties runProperties20 = new RunProperties();
            RunFonts runFonts18 = new RunFonts(){ Hint = FontTypeHintValues.EastAsia };

            runProperties20.Append(runFonts18);
            Text text9 = new Text();
            text9.Text = "repeatingSectionItem";

            run9.Append(runProperties20);
            run9.Append(text9);
            ProofError proofError3 = new ProofError(){ Type = ProofingErrorValues.SpellEnd };
            ProofError proofError4 = new ProofError(){ Type = ProofingErrorValues.GrammarEnd };

            paragraph9.Append(proofError1);
            paragraph9.Append(proofError2);
            paragraph9.Append(run9);
            paragraph9.Append(proofError3);
            paragraph9.Append(proofError4);

            sdtContentBlock11.Append(paragraph9);

            sdtBlock11.Append(sdtProperties11);
            sdtBlock11.Append(sdtEndCharProperties11);
            sdtBlock11.Append(sdtContentBlock11);

            sdtContentBlock10.Append(sdtBlock11);

            sdtBlock10.Append(sdtProperties10);
            sdtBlock10.Append(sdtEndCharProperties10);
            sdtBlock10.Append(sdtContentBlock10);

            SdtBlock sdtBlock12 = new SdtBlock();

            SdtProperties sdtProperties12 = new SdtProperties();

            RunProperties runProperties21 = new RunProperties();
            RunFonts runFonts19 = new RunFonts(){ Hint = FontTypeHintValues.EastAsia };

            runProperties21.Append(runFonts19);
            SdtAlias sdtAlias10 = new SdtAlias(){ Val = "Test1.4.3" };
            Tag tag10 = new Tag(){ Val = "Test1.4.3" };
            SdtId sdtId12 = new SdtId(){ Val = -294221661 };

            W15.SdtRepeatedSection sdtRepeatedSection3 = new W15.SdtRepeatedSection();
            W15.DoNotAllowInsertDeleteSection doNotAllowInsertDeleteSection1 = new W15.DoNotAllowInsertDeleteSection(){ Val = true };

            sdtRepeatedSection3.Append(doNotAllowInsertDeleteSection1);

            sdtProperties12.Append(runProperties21);
            sdtProperties12.Append(sdtAlias10);
            sdtProperties12.Append(tag10);
            sdtProperties12.Append(sdtId12);
            sdtProperties12.Append(sdtRepeatedSection3);
            SdtEndCharProperties sdtEndCharProperties12 = new SdtEndCharProperties();

            SdtContentBlock sdtContentBlock12 = new SdtContentBlock();

            SdtBlock sdtBlock13 = new SdtBlock();

            SdtProperties sdtProperties13 = new SdtProperties();

            RunProperties runProperties22 = new RunProperties();
            RunFonts runFonts20 = new RunFonts(){ Hint = FontTypeHintValues.EastAsia };

            runProperties22.Append(runFonts20);
            SdtId sdtId13 = new SdtId(){ Val = 2112001363 };
            Lock lock1 = new Lock(){ Val = LockingValues.SdtLocked };

            SdtPlaceholder sdtPlaceholder10 = new SdtPlaceholder();
            DocPartReference docPartReference10 = new DocPartReference(){ Val = "DefaultPlaceholder_1081868562" };

            sdtPlaceholder10.Append(docPartReference10);
            W15.SdtRepeatedSectionItem sdtRepeatedSectionItem3 = new W15.SdtRepeatedSectionItem();

            sdtProperties13.Append(runProperties22);
            sdtProperties13.Append(sdtId13);
            sdtProperties13.Append(lock1);
            sdtProperties13.Append(sdtPlaceholder10);
            sdtProperties13.Append(sdtRepeatedSectionItem3);
            SdtEndCharProperties sdtEndCharProperties13 = new SdtEndCharProperties();

            SdtContentBlock sdtContentBlock13 = new SdtContentBlock();

            Paragraph paragraph10 = new Paragraph(){ RsidParagraphAddition = "000010BA", RsidRunAdditionDefault = "000010BA" };
            ProofError proofError5 = new ProofError(){ Type = ProofingErrorValues.SpellStart };
            ProofError proofError6 = new ProofError(){ Type = ProofingErrorValues.GrammarStart };

            Run run10 = new Run();

            RunProperties runProperties23 = new RunProperties();
            RunFonts runFonts21 = new RunFonts(){ Hint = FontTypeHintValues.EastAsia };

            runProperties23.Append(runFonts21);
            Text text10 = new Text();
            text10.Text = "doNotAllowInsertDeleteSection";

            run10.Append(runProperties23);
            run10.Append(text10);
            ProofError proofError7 = new ProofError(){ Type = ProofingErrorValues.SpellEnd };
            ProofError proofError8 = new ProofError(){ Type = ProofingErrorValues.GrammarEnd };

            paragraph10.Append(proofError5);
            paragraph10.Append(proofError6);
            paragraph10.Append(run10);
            paragraph10.Append(proofError7);
            paragraph10.Append(proofError8);

            sdtContentBlock13.Append(paragraph10);

            sdtBlock13.Append(sdtProperties13);
            sdtBlock13.Append(sdtEndCharProperties13);
            sdtBlock13.Append(sdtContentBlock13);

            sdtContentBlock12.Append(sdtBlock13);

            sdtBlock12.Append(sdtProperties12);
            sdtBlock12.Append(sdtEndCharProperties12);
            sdtBlock12.Append(sdtContentBlock12);

            SdtBlock sdtBlock14 = new SdtBlock();

            SdtProperties sdtProperties14 = new SdtProperties();

            RunProperties runProperties24 = new RunProperties();
            RunFonts runFonts22 = new RunFonts(){ Hint = FontTypeHintValues.EastAsia };

            runProperties24.Append(runFonts22);
            SdtAlias sdtAlias11 = new SdtAlias(){ Val = "Test1.4.4" };
            Tag tag11 = new Tag(){ Val = "Test1.4.4" };
            SdtId sdtId14 = new SdtId(){ Val = -248501389 };

            W15.SdtRepeatedSection sdtRepeatedSection4 = new W15.SdtRepeatedSection();
            W15.SectionTitle sectionTitle1 = new W15.SectionTitle(){ Val = "Section title string" };

            sdtRepeatedSection4.Append(sectionTitle1);

            sdtProperties14.Append(runProperties24);
            sdtProperties14.Append(sdtAlias11);
            sdtProperties14.Append(tag11);
            sdtProperties14.Append(sdtId14);
            sdtProperties14.Append(sdtRepeatedSection4);
            SdtEndCharProperties sdtEndCharProperties14 = new SdtEndCharProperties();

            SdtContentBlock sdtContentBlock14 = new SdtContentBlock();

            SdtBlock sdtBlock15 = new SdtBlock();

            SdtProperties sdtProperties15 = new SdtProperties();

            RunProperties runProperties25 = new RunProperties();
            RunFonts runFonts23 = new RunFonts(){ Hint = FontTypeHintValues.EastAsia };

            runProperties25.Append(runFonts23);
            SdtId sdtId15 = new SdtId(){ Val = 1971018620 };

            SdtPlaceholder sdtPlaceholder11 = new SdtPlaceholder();
            DocPartReference docPartReference11 = new DocPartReference(){ Val = "DefaultPlaceholder_1081868562" };

            sdtPlaceholder11.Append(docPartReference11);
            W15.SdtRepeatedSectionItem sdtRepeatedSectionItem4 = new W15.SdtRepeatedSectionItem();

            sdtProperties15.Append(runProperties25);
            sdtProperties15.Append(sdtId15);
            sdtProperties15.Append(sdtPlaceholder11);
            sdtProperties15.Append(sdtRepeatedSectionItem4);
            SdtEndCharProperties sdtEndCharProperties15 = new SdtEndCharProperties();

            SdtContentBlock sdtContentBlock15 = new SdtContentBlock();

            Paragraph paragraph11 = new Paragraph(){ RsidParagraphAddition = "000010BA", RsidRunAdditionDefault = "000010BA" };
            ProofError proofError9 = new ProofError(){ Type = ProofingErrorValues.SpellStart };
            ProofError proofError10 = new ProofError(){ Type = ProofingErrorValues.GrammarStart };

            Run run11 = new Run();

            RunProperties runProperties26 = new RunProperties();
            RunFonts runFonts24 = new RunFonts(){ Hint = FontTypeHintValues.EastAsia };

            runProperties26.Append(runFonts24);
            Text text11 = new Text();
            text11.Text = "sectionTitle";

            run11.Append(runProperties26);
            run11.Append(text11);
            ProofError proofError11 = new ProofError(){ Type = ProofingErrorValues.SpellEnd };
            ProofError proofError12 = new ProofError(){ Type = ProofingErrorValues.GrammarEnd };

            paragraph11.Append(proofError9);
            paragraph11.Append(proofError10);
            paragraph11.Append(run11);
            paragraph11.Append(proofError11);
            paragraph11.Append(proofError12);

            sdtContentBlock15.Append(paragraph11);

            sdtBlock15.Append(sdtProperties15);
            sdtBlock15.Append(sdtEndCharProperties15);
            sdtBlock15.Append(sdtContentBlock15);

            sdtContentBlock14.Append(sdtBlock15);

            sdtBlock14.Append(sdtProperties14);
            sdtBlock14.Append(sdtEndCharProperties14);
            sdtBlock14.Append(sdtContentBlock14);

            Table table1 = new Table();

            TableProperties tableProperties1 = new TableProperties();
            TableWidth tableWidth1 = new TableWidth(){ Width = "0", Type = TableWidthUnitValues.Auto };

            TableBorders tableBorders1 = new TableBorders();
            TopBorder topBorder1 = new TopBorder(){ Val = BorderValues.Double, Color = "auto", Size = (UInt32Value)4U, Space = (UInt32Value)0U };
            LeftBorder leftBorder1 = new LeftBorder(){ Val = BorderValues.Double, Color = "auto", Size = (UInt32Value)4U, Space = (UInt32Value)0U };
            BottomBorder bottomBorder1 = new BottomBorder(){ Val = BorderValues.Double, Color = "auto", Size = (UInt32Value)4U, Space = (UInt32Value)0U };
            RightBorder rightBorder1 = new RightBorder(){ Val = BorderValues.Double, Color = "auto", Size = (UInt32Value)4U, Space = (UInt32Value)0U };
            InsideHorizontalBorder insideHorizontalBorder1 = new InsideHorizontalBorder(){ Val = BorderValues.Single, Color = "auto", Size = (UInt32Value)4U, Space = (UInt32Value)0U };
            InsideVerticalBorder insideVerticalBorder1 = new InsideVerticalBorder(){ Val = BorderValues.Single, Color = "auto", Size = (UInt32Value)4U, Space = (UInt32Value)0U };

            tableBorders1.Append(topBorder1);
            tableBorders1.Append(leftBorder1);
            tableBorders1.Append(bottomBorder1);
            tableBorders1.Append(rightBorder1);
            tableBorders1.Append(insideHorizontalBorder1);
            tableBorders1.Append(insideVerticalBorder1);
            TableLayout tableLayout1 = new TableLayout(){ Type = TableLayoutValues.Fixed };
            TableLook tableLook1 = new TableLook(){ Val = "0000" };

            tableProperties1.Append(tableWidth1);
            tableProperties1.Append(tableBorders1);
            tableProperties1.Append(tableLayout1);
            tableProperties1.Append(tableLook1);

            TableGrid tableGrid1 = new TableGrid();
            GridColumn gridColumn1 = new GridColumn(){ Width = "4788" };
            GridColumn gridColumn2 = new GridColumn(){ Width = "4788" };

            tableGrid1.Append(gridColumn1);
            tableGrid1.Append(gridColumn2);

            SdtRow sdtRow1 = new SdtRow();

            SdtProperties sdtProperties16 = new SdtProperties();
            SdtId sdtId16 = new SdtId(){ Val = 1391384564 };

            SdtPlaceholder sdtPlaceholder12 = new SdtPlaceholder();
            DocPartReference docPartReference12 = new DocPartReference(){ Val = "B207B2DF6D0E4E13956E6616811860CA" };

            sdtPlaceholder12.Append(docPartReference12);
            W15.DataBinding dataBinding1 = new W15.DataBinding(){ XPath = "/books[1]/book", StoreItemId = "{F6DB09CA-2A79-464E-B71A-D37E08A01059}" };
            W15.Appearance appearance3 = new W15.Appearance(){ Val = W15.SdtAppearance.Tags };
            W15.SdtRepeatedSection sdtRepeatedSection5 = new W15.SdtRepeatedSection();

            sdtProperties16.Append(sdtId16);
            sdtProperties16.Append(sdtPlaceholder12);
            sdtProperties16.Append(dataBinding1);
            sdtProperties16.Append(appearance3);
            sdtProperties16.Append(sdtRepeatedSection5);
            SdtEndCharProperties sdtEndCharProperties16 = new SdtEndCharProperties();

            SdtContentRow sdtContentRow1 = new SdtContentRow();

            SdtRow sdtRow2 = new SdtRow();

            SdtProperties sdtProperties17 = new SdtProperties();
            SdtId sdtId17 = new SdtId(){ Val = 1787311118 };
            W15.Appearance appearance4 = new W15.Appearance(){ Val = W15.SdtAppearance.Tags };
            W15.SdtRepeatedSectionItem sdtRepeatedSectionItem5 = new W15.SdtRepeatedSectionItem();

            sdtProperties17.Append(sdtId17);
            sdtProperties17.Append(appearance4);
            sdtProperties17.Append(sdtRepeatedSectionItem5);
            SdtEndCharProperties sdtEndCharProperties17 = new SdtEndCharProperties();

            SdtContentRow sdtContentRow2 = new SdtContentRow();

            TableRow tableRow1 = new TableRow(){ RsidTableRowAddition = "00E930A2", RsidTableRowProperties = "00242789" };

            SdtCell sdtCell1 = new SdtCell();

            SdtProperties sdtProperties18 = new SdtProperties();
            SdtAlias sdtAlias12 = new SdtAlias(){ Val = "Test1.5.1_1" };
            Tag tag12 = new Tag(){ Val = "Test1.5.1_1" };
            SdtId sdtId18 = new SdtId(){ Val = -1276551752 };

            SdtPlaceholder sdtPlaceholder13 = new SdtPlaceholder();
            DocPartReference docPartReference13 = new DocPartReference(){ Val = "B207B2DF6D0E4E13956E6616811860CA" };

            sdtPlaceholder13.Append(docPartReference13);
            DataBinding dataBinding2 = new DataBinding(){ XPath = "/books[1]/book[1]/title[1]", StoreItemId = "{F6DB09CA-2A79-464E-B71A-D37E08A01059}" };
            SdtContentText sdtContentText8 = new SdtContentText();

            sdtProperties18.Append(sdtAlias12);
            sdtProperties18.Append(tag12);
            sdtProperties18.Append(sdtId18);
            sdtProperties18.Append(sdtPlaceholder13);
            sdtProperties18.Append(dataBinding2);
            sdtProperties18.Append(sdtContentText8);
            SdtEndCharProperties sdtEndCharProperties18 = new SdtEndCharProperties();

            SdtContentCell sdtContentCell1 = new SdtContentCell();

            TableCell tableCell1 = new TableCell();

            TableCellProperties tableCellProperties1 = new TableCellProperties();
            TableCellWidth tableCellWidth1 = new TableCellWidth(){ Width = "4788", Type = TableWidthUnitValues.Dxa };
            Shading shading1 = new Shading(){ Val = ShadingPatternValues.Clear, Color = "auto", Fill = "auto" };

            tableCellProperties1.Append(tableCellWidth1);
            tableCellProperties1.Append(shading1);

            Paragraph paragraph12 = new Paragraph(){ RsidParagraphAddition = "00E930A2", RsidParagraphProperties = "00E86739", RsidRunAdditionDefault = "00E930A2" };

            Run run12 = new Run();

            RunProperties runProperties27 = new RunProperties();
            RunFonts runFonts25 = new RunFonts(){ Hint = FontTypeHintValues.EastAsia };

            runProperties27.Append(runFonts25);
            Text text12 = new Text();
            text12.Text = "Repeating Section,Row1";

            run12.Append(runProperties27);
            run12.Append(text12);

            Run run13 = new Run(){ RsidRunAddition = "00E86739" };

            RunProperties runProperties28 = new RunProperties();
            RunFonts runFonts26 = new RunFonts(){ Hint = FontTypeHintValues.EastAsia };

            runProperties28.Append(runFonts26);
            Text text13 = new Text();
            text13.Text = ",Cell1";

            run13.Append(runProperties28);
            run13.Append(text13);

            paragraph12.Append(run12);
            paragraph12.Append(run13);

            tableCell1.Append(tableCellProperties1);
            tableCell1.Append(paragraph12);

            sdtContentCell1.Append(tableCell1);

            sdtCell1.Append(sdtProperties18);
            sdtCell1.Append(sdtEndCharProperties18);
            sdtCell1.Append(sdtContentCell1);

            SdtCell sdtCell2 = new SdtCell();

            SdtProperties sdtProperties19 = new SdtProperties();

            RunProperties runProperties29 = new RunProperties();
            Kern kern1 = new Kern(){ Val = (UInt32Value)0U };

            runProperties29.Append(kern1);
            SdtAlias sdtAlias13 = new SdtAlias(){ Val = "Test1.5.1_2" };
            Tag tag13 = new Tag(){ Val = "Test1.5.1_2" };
            SdtId sdtId19 = new SdtId(){ Val = -1317331761 };

            SdtPlaceholder sdtPlaceholder14 = new SdtPlaceholder();
            DocPartReference docPartReference14 = new DocPartReference(){ Val = "B207B2DF6D0E4E13956E6616811860CA" };

            sdtPlaceholder14.Append(docPartReference14);
            DataBinding dataBinding3 = new DataBinding(){ XPath = "/books[1]/book[1]/author[1]", StoreItemId = "{F6DB09CA-2A79-464E-B71A-D37E08A01059}" };
            SdtContentText sdtContentText9 = new SdtContentText();

            sdtProperties19.Append(runProperties29);
            sdtProperties19.Append(sdtAlias13);
            sdtProperties19.Append(tag13);
            sdtProperties19.Append(sdtId19);
            sdtProperties19.Append(sdtPlaceholder14);
            sdtProperties19.Append(dataBinding3);
            sdtProperties19.Append(sdtContentText9);
            SdtEndCharProperties sdtEndCharProperties19 = new SdtEndCharProperties();

            SdtContentCell sdtContentCell2 = new SdtContentCell();

            TableCell tableCell2 = new TableCell();

            TableCellProperties tableCellProperties2 = new TableCellProperties();
            TableCellWidth tableCellWidth2 = new TableCellWidth(){ Width = "4788", Type = TableWidthUnitValues.Dxa };
            Shading shading2 = new Shading(){ Val = ShadingPatternValues.Clear, Color = "auto", Fill = "auto" };

            tableCellProperties2.Append(tableCellWidth2);
            tableCellProperties2.Append(shading2);

            Paragraph paragraph13 = new Paragraph(){ RsidParagraphAddition = "00E930A2", RsidParagraphProperties = "00E86739", RsidRunAdditionDefault = "00E930A2" };

            Run run14 = new Run();

            RunProperties runProperties30 = new RunProperties();
            Kern kern2 = new Kern(){ Val = (UInt32Value)0U };

            runProperties30.Append(kern2);
            Text text14 = new Text();
            text14.Text = "Repeating Section";

            run14.Append(runProperties30);
            run14.Append(text14);

            Run run15 = new Run(){ RsidRunAddition = "00E86739" };

            RunProperties runProperties31 = new RunProperties();
            RunFonts runFonts27 = new RunFonts(){ Hint = FontTypeHintValues.EastAsia };
            Kern kern3 = new Kern(){ Val = (UInt32Value)0U };

            runProperties31.Append(runFonts27);
            runProperties31.Append(kern3);
            Text text15 = new Text();
            text15.Text = ",";

            run15.Append(runProperties31);
            run15.Append(text15);

            Run run16 = new Run();

            RunProperties runProperties32 = new RunProperties();
            Kern kern4 = new Kern(){ Val = (UInt32Value)0U };

            runProperties32.Append(kern4);
            Text text16 = new Text();
            text16.Text = "Row1";

            run16.Append(runProperties32);
            run16.Append(text16);

            Run run17 = new Run(){ RsidRunAddition = "00E86739" };

            RunProperties runProperties33 = new RunProperties();
            RunFonts runFonts28 = new RunFonts(){ Hint = FontTypeHintValues.EastAsia };
            Kern kern5 = new Kern(){ Val = (UInt32Value)0U };

            runProperties33.Append(runFonts28);
            runProperties33.Append(kern5);
            Text text17 = new Text();
            text17.Text = ",Cell2";

            run17.Append(runProperties33);
            run17.Append(text17);

            paragraph13.Append(run14);
            paragraph13.Append(run15);
            paragraph13.Append(run16);
            paragraph13.Append(run17);

            tableCell2.Append(tableCellProperties2);
            tableCell2.Append(paragraph13);

            sdtContentCell2.Append(tableCell2);

            sdtCell2.Append(sdtProperties19);
            sdtCell2.Append(sdtEndCharProperties19);
            sdtCell2.Append(sdtContentCell2);

            tableRow1.Append(sdtCell1);
            tableRow1.Append(sdtCell2);

            sdtContentRow2.Append(tableRow1);

            sdtRow2.Append(sdtProperties17);
            sdtRow2.Append(sdtEndCharProperties17);
            sdtRow2.Append(sdtContentRow2);

            SdtRow sdtRow3 = new SdtRow();

            SdtProperties sdtProperties20 = new SdtProperties();
            SdtId sdtId20 = new SdtId(){ Val = 689805002 };
            W15.Appearance appearance5 = new W15.Appearance(){ Val = W15.SdtAppearance.Tags };
            W15.SdtRepeatedSectionItem sdtRepeatedSectionItem6 = new W15.SdtRepeatedSectionItem();

            sdtProperties20.Append(sdtId20);
            sdtProperties20.Append(appearance5);
            sdtProperties20.Append(sdtRepeatedSectionItem6);
            SdtEndCharProperties sdtEndCharProperties20 = new SdtEndCharProperties();

            SdtContentRow sdtContentRow3 = new SdtContentRow();

            TableRow tableRow2 = new TableRow(){ RsidTableRowAddition = "00E930A2", RsidTableRowProperties = "00242789" };

            SdtCell sdtCell3 = new SdtCell();

            SdtProperties sdtProperties21 = new SdtProperties();
            SdtAlias sdtAlias14 = new SdtAlias(){ Val = "Test1.5.1_3" };
            Tag tag14 = new Tag(){ Val = "Test1.5.1_3" };
            SdtId sdtId21 = new SdtId(){ Val = 880594776 };

            SdtPlaceholder sdtPlaceholder15 = new SdtPlaceholder();
            DocPartReference docPartReference15 = new DocPartReference(){ Val = "4B632797D8B1461898B8F461443A20E0" };

            sdtPlaceholder15.Append(docPartReference15);
            DataBinding dataBinding4 = new DataBinding(){ XPath = "/books[1]/book[4]/title[1]", StoreItemId = "{F6DB09CA-2A79-464E-B71A-D37E08A01059}" };
            SdtContentText sdtContentText10 = new SdtContentText();

            sdtProperties21.Append(sdtAlias14);
            sdtProperties21.Append(tag14);
            sdtProperties21.Append(sdtId21);
            sdtProperties21.Append(sdtPlaceholder15);
            sdtProperties21.Append(dataBinding4);
            sdtProperties21.Append(sdtContentText10);

            SdtEndCharProperties sdtEndCharProperties21 = new SdtEndCharProperties();

            RunProperties runProperties34 = new RunProperties();
            Kern kern6 = new Kern(){ Val = (UInt32Value)0U };

            runProperties34.Append(kern6);

            sdtEndCharProperties21.Append(runProperties34);

            SdtContentCell sdtContentCell3 = new SdtContentCell();

            TableCell tableCell3 = new TableCell();

            TableCellProperties tableCellProperties3 = new TableCellProperties();
            TableCellWidth tableCellWidth3 = new TableCellWidth(){ Width = "4788", Type = TableWidthUnitValues.Dxa };
            Shading shading3 = new Shading(){ Val = ShadingPatternValues.Clear, Color = "auto", Fill = "auto" };

            tableCellProperties3.Append(tableCellWidth3);
            tableCellProperties3.Append(shading3);

            Paragraph paragraph14 = new Paragraph(){ RsidParagraphAddition = "00E930A2", RsidParagraphProperties = "00E86739", RsidRunAdditionDefault = "00E930A2" };

            Run run18 = new Run();

            RunProperties runProperties35 = new RunProperties();
            Kern kern7 = new Kern(){ Val = (UInt32Value)0U };

            runProperties35.Append(kern7);
            Text text18 = new Text();
            text18.Text = "Repeating Section";

            run18.Append(runProperties35);
            run18.Append(text18);

            Run run19 = new Run(){ RsidRunAddition = "00E86739" };

            RunProperties runProperties36 = new RunProperties();
            RunFonts runFonts29 = new RunFonts(){ Hint = FontTypeHintValues.EastAsia };
            Kern kern8 = new Kern(){ Val = (UInt32Value)0U };

            runProperties36.Append(runFonts29);
            runProperties36.Append(kern8);
            Text text19 = new Text();
            text19.Text = ",";

            run19.Append(runProperties36);
            run19.Append(text19);

            Run run20 = new Run();

            RunProperties runProperties37 = new RunProperties();
            Kern kern9 = new Kern(){ Val = (UInt32Value)0U };

            runProperties37.Append(kern9);
            Text text20 = new Text();
            text20.Text = "Row";

            run20.Append(runProperties37);
            run20.Append(text20);

            Run run21 = new Run();

            RunProperties runProperties38 = new RunProperties();
            RunFonts runFonts30 = new RunFonts(){ Hint = FontTypeHintValues.EastAsia };
            Kern kern10 = new Kern(){ Val = (UInt32Value)0U };

            runProperties38.Append(runFonts30);
            runProperties38.Append(kern10);
            Text text21 = new Text();
            text21.Text = "2";

            run21.Append(runProperties38);
            run21.Append(text21);

            Run run22 = new Run(){ RsidRunAddition = "00E86739" };

            RunProperties runProperties39 = new RunProperties();
            RunFonts runFonts31 = new RunFonts(){ Hint = FontTypeHintValues.EastAsia };
            Kern kern11 = new Kern(){ Val = (UInt32Value)0U };

            runProperties39.Append(runFonts31);
            runProperties39.Append(kern11);
            Text text22 = new Text();
            text22.Text = ",Cell1";

            run22.Append(runProperties39);
            run22.Append(text22);

            paragraph14.Append(run18);
            paragraph14.Append(run19);
            paragraph14.Append(run20);
            paragraph14.Append(run21);
            paragraph14.Append(run22);

            tableCell3.Append(tableCellProperties3);
            tableCell3.Append(paragraph14);

            sdtContentCell3.Append(tableCell3);

            sdtCell3.Append(sdtProperties21);
            sdtCell3.Append(sdtEndCharProperties21);
            sdtCell3.Append(sdtContentCell3);

            SdtCell sdtCell4 = new SdtCell();

            SdtProperties sdtProperties22 = new SdtProperties();

            RunProperties runProperties40 = new RunProperties();
            Kern kern12 = new Kern(){ Val = (UInt32Value)0U };

            runProperties40.Append(kern12);
            SdtAlias sdtAlias15 = new SdtAlias(){ Val = "Test1.5.1_4" };
            Tag tag15 = new Tag(){ Val = "Test1.5.1_4" };
            SdtId sdtId22 = new SdtId(){ Val = -1022928317 };

            SdtPlaceholder sdtPlaceholder16 = new SdtPlaceholder();
            DocPartReference docPartReference16 = new DocPartReference(){ Val = "4B632797D8B1461898B8F461443A20E0" };

            sdtPlaceholder16.Append(docPartReference16);
            DataBinding dataBinding5 = new DataBinding(){ XPath = "/books[1]/book[4]/author[1]", StoreItemId = "{F6DB09CA-2A79-464E-B71A-D37E08A01059}" };
            SdtContentText sdtContentText11 = new SdtContentText();

            sdtProperties22.Append(runProperties40);
            sdtProperties22.Append(sdtAlias15);
            sdtProperties22.Append(tag15);
            sdtProperties22.Append(sdtId22);
            sdtProperties22.Append(sdtPlaceholder16);
            sdtProperties22.Append(dataBinding5);
            sdtProperties22.Append(sdtContentText11);
            SdtEndCharProperties sdtEndCharProperties22 = new SdtEndCharProperties();

            SdtContentCell sdtContentCell4 = new SdtContentCell();

            TableCell tableCell4 = new TableCell();

            TableCellProperties tableCellProperties4 = new TableCellProperties();
            TableCellWidth tableCellWidth4 = new TableCellWidth(){ Width = "4788", Type = TableWidthUnitValues.Dxa };
            Shading shading4 = new Shading(){ Val = ShadingPatternValues.Clear, Color = "auto", Fill = "auto" };

            tableCellProperties4.Append(tableCellWidth4);
            tableCellProperties4.Append(shading4);

            Paragraph paragraph15 = new Paragraph(){ RsidParagraphAddition = "00E930A2", RsidParagraphProperties = "00E86739", RsidRunAdditionDefault = "009651D6" };

            Run run23 = new Run();

            RunProperties runProperties41 = new RunProperties();
            Kern kern13 = new Kern(){ Val = (UInt32Value)0U };

            runProperties41.Append(kern13);
            Text text23 = new Text();
            text23.Text = "Repeating Section";

            run23.Append(runProperties41);
            run23.Append(text23);

            Run run24 = new Run(){ RsidRunAddition = "00E86739" };

            RunProperties runProperties42 = new RunProperties();
            RunFonts runFonts32 = new RunFonts(){ Hint = FontTypeHintValues.EastAsia };
            Kern kern14 = new Kern(){ Val = (UInt32Value)0U };

            runProperties42.Append(runFonts32);
            runProperties42.Append(kern14);
            Text text24 = new Text();
            text24.Text = ",Row2,Cell2";

            run24.Append(runProperties42);
            run24.Append(text24);

            paragraph15.Append(run23);
            paragraph15.Append(run24);

            tableCell4.Append(tableCellProperties4);
            tableCell4.Append(paragraph15);

            sdtContentCell4.Append(tableCell4);

            sdtCell4.Append(sdtProperties22);
            sdtCell4.Append(sdtEndCharProperties22);
            sdtCell4.Append(sdtContentCell4);

            tableRow2.Append(sdtCell3);
            tableRow2.Append(sdtCell4);

            sdtContentRow3.Append(tableRow2);

            sdtRow3.Append(sdtProperties20);
            sdtRow3.Append(sdtEndCharProperties20);
            sdtRow3.Append(sdtContentRow3);

            sdtContentRow1.Append(sdtRow2);
            sdtContentRow1.Append(sdtRow3);

            sdtRow1.Append(sdtProperties16);
            sdtRow1.Append(sdtEndCharProperties16);
            sdtRow1.Append(sdtContentRow1);

            TableRow tableRow3 = new TableRow(){ RsidTableRowAddition = "00E930A2", RsidTableRowProperties = "00242789" };

            TableCell tableCell5 = new TableCell();

            TableCellProperties tableCellProperties5 = new TableCellProperties();
            TableCellWidth tableCellWidth5 = new TableCellWidth(){ Width = "4788", Type = TableWidthUnitValues.Dxa };
            Shading shading5 = new Shading(){ Val = ShadingPatternValues.Clear, Color = "auto", Fill = "auto" };

            tableCellProperties5.Append(tableCellWidth5);
            tableCellProperties5.Append(shading5);
            Paragraph paragraph16 = new Paragraph(){ RsidParagraphAddition = "00E930A2", RsidParagraphProperties = "00242789", RsidRunAdditionDefault = "00E930A2" };

            tableCell5.Append(tableCellProperties5);
            tableCell5.Append(paragraph16);

            TableCell tableCell6 = new TableCell();

            TableCellProperties tableCellProperties6 = new TableCellProperties();
            TableCellWidth tableCellWidth6 = new TableCellWidth(){ Width = "4788", Type = TableWidthUnitValues.Dxa };
            Shading shading6 = new Shading(){ Val = ShadingPatternValues.Clear, Color = "auto", Fill = "auto" };

            tableCellProperties6.Append(tableCellWidth6);
            tableCellProperties6.Append(shading6);
            Paragraph paragraph17 = new Paragraph(){ RsidParagraphAddition = "00E930A2", RsidParagraphProperties = "00242789", RsidRunAdditionDefault = "00E930A2" };

            tableCell6.Append(tableCellProperties6);
            tableCell6.Append(paragraph17);

            tableRow3.Append(tableCell5);
            tableRow3.Append(tableCell6);

            table1.Append(tableProperties1);
            table1.Append(tableGrid1);
            table1.Append(sdtRow1);
            table1.Append(tableRow3);
            Paragraph paragraph18 = new Paragraph(){ RsidParagraphAddition = "00E930A2", RsidRunAdditionDefault = "00E930A2" };

            SectionProperties sectionProperties1 = new SectionProperties(){ RsidR = "00E930A2" };
            PageSize pageSize1 = new PageSize(){ Width = (UInt32Value)11906U, Height = (UInt32Value)16838U };
            PageMargin pageMargin1 = new PageMargin(){ Top = 1985, Right = (UInt32Value)1701U, Bottom = 1701, Left = (UInt32Value)1701U, Header = (UInt32Value)851U, Footer = (UInt32Value)992U, Gutter = (UInt32Value)0U };
            Columns columns1 = new Columns(){ Space = "425" };
            DocGrid docGrid1 = new DocGrid(){ Type = DocGridValues.Lines, LinePitch = 360 };

            sectionProperties1.Append(pageSize1);
            sectionProperties1.Append(pageMargin1);
            sectionProperties1.Append(columns1);
            sectionProperties1.Append(docGrid1);

            body1.Append(sdtBlock1);
            body1.Append(sdtBlock2);
            body1.Append(sdtBlock3);
            body1.Append(sdtBlock4);
            body1.Append(sdtBlock5);
            body1.Append(sdtBlock6);
            body1.Append(sdtBlock7);
            body1.Append(sdtBlock8);
            body1.Append(sdtBlock10);
            body1.Append(sdtBlock12);
            body1.Append(sdtBlock14);
            body1.Append(table1);
            body1.Append(paragraph18);
            body1.Append(sectionProperties1);

            document1.Append(body1);

            mainDocumentPart1.Document = document1;
        }
        public static WordprocessingDocument InsertImages(this WordprocessingDocument doc, ClientContext clientContext, string contentControlTag, string attachementServerRelativeUrl, TraceWriter log, List <string> messages)
        {
            try
            {
                SdtElement cc = doc.MainDocumentPart.Document.Body.Descendants <SdtElement>().FirstOrDefault(c =>
                {
                    SdtProperties p = c.Elements <SdtProperties>().FirstOrDefault();
                    if (p != null)
                    {
                        // Is it a picture content control?
                        SdtContentPicture pict = p.Elements <SdtContentPicture>().FirstOrDefault();
                        // Get the alias.
                        SdtAlias a = p.Elements <SdtAlias>().FirstOrDefault();

                        if (pict != null && a.Val == contentControlTag)
                        {
                            return(true);
                        }
                    }
                    return(false);
                });
                string embed = null;
                if (cc != null)
                {
                    Drawing dr = cc.Descendants <Drawing>().FirstOrDefault();
                    if (dr != null)
                    {
                        DocumentFormat.OpenXml.Drawing.Blip blip = dr.Descendants <DocumentFormat.OpenXml.Drawing.Blip>().FirstOrDefault();
                        if (blip != null)
                        {
                            embed = blip.Embed;
                        }
                    }
                }
                if (embed != null)
                {
                    IdPartPair idpp = doc.MainDocumentPart.Parts
                                      .Where(pa => pa.RelationshipId == embed).FirstOrDefault();
                    if (idpp != null)
                    {
                        ImagePart ip             = (ImagePart)idpp.OpenXmlPart;
                        var       attachmentFile = clientContext.Site.RootWeb.GetFileByServerRelativeUrl(attachementServerRelativeUrl);
                        clientContext.Load(attachmentFile);
                        clientContext.ExecuteQueryRetry();
                        if (attachmentFile != null)
                        {
                            // Returns required result
                            ClientResult <Stream> attachmentStream = attachmentFile.OpenBinaryStream();
                            clientContext.ExecuteQueryRetry();
                            ip.FeedData(attachmentStream.Value);
                        }
                    }
                }
                return(doc);
            }
            catch (Exception ex)
            {
                string message = $"An error occurred replacing Image Content Control Tag \"{contentControlTag}\". Please ensure its an Image Content Control, and the value is the server relative url of an image file that you have access to";
                log.Info(message);
                messages.Add(message);
                return(doc);
            }
        }
예제 #7
0
        /// <summary>
        /// FillDataObject
        /// </summary>
        /// <param name="dataInputObject"></param>
        /// <param name="stream"></param>
        public void FillDataObject(object dataInputObject, Stream stream)
        {
            if (dataInputObject != null)
            {
                if (stream != null && stream.CanRead && stream.CanWrite)
                {
                    // Use OpenXML to process
                    var dictionary = GetDictionaryFromObject(dataInputObject);
                    using (WordprocessingDocument word = WordprocessingDocument.Open(stream, true))
                    {
                        var part     = word.MainDocumentPart;
                        var elements = part.Document.Descendants <SdtElement>().ToList();
                        foreach (SdtElement element in elements)
                        {
                            SdtAlias alias = element.Descendants <SdtAlias>().FirstOrDefault();
                            if (alias != null)
                            {
                                // Get title of content control
                                var title = alias.Val.Value;
                                if (dictionary.ContainsKey(title))
                                {
                                    object value = dictionary[title];
                                    if (element.ToString().Equals("DocumentFormat.OpenXml.Wordprocessing.SdtRun"))
                                    {
                                        SdtRun run = element as SdtRun;
                                        if (run != null)
                                        {
                                            SdtContentRun contentRun = run.Descendants <SdtContentRun>().FirstOrDefault();
                                            Run           xRun       = contentRun.Descendants <Run>().FirstOrDefault();
                                            if (xRun == null)
                                            {
                                                contentRun.AppendChild(new Run());
                                                xRun = contentRun.Descendants <Run>().FirstOrDefault();
                                            }
                                            Text text = xRun.Descendants <Text>().FirstOrDefault();
                                            if (text == null)
                                            {
                                                xRun.AppendChild(new Text(value.ToString()));
                                                text = xRun.Descendants <Text>().FirstOrDefault();
                                            }
                                            text.Text = value.ToString();
                                        }
                                    }
                                    else if (element.ToString().Equals("DocumentFormat.OpenXml.Wordprocessing.SdtBlock"))
                                    {
                                        SdtBlock block = element as SdtBlock;
                                        if (block != null)
                                        {
                                            SdtContentBlock contentBlock = block.Descendants <SdtContentBlock>().FirstOrDefault();
                                            Run             xRun         = contentBlock.Descendants <Run>().FirstOrDefault();
                                            if (xRun == null)
                                            {
                                                contentBlock.AppendChild(new Run());
                                                xRun = contentBlock.Descendants <Run>().FirstOrDefault();
                                            }
                                            Text text = xRun.Descendants <Text>().FirstOrDefault();
                                            if (text == null)
                                            {
                                                xRun.AppendChild(new Text(value.ToString()));
                                                text = xRun.Descendants <Text>().FirstOrDefault();
                                            }
                                            text.Text = value.ToString();
                                        }
                                    }
                                }
                            }
                        }

                        part.Document.Save();
                    }
                }
            }
        }
예제 #8
0
        /// <summary>
        /// Fill data object into word file that has arrBytesSource data.
        /// </summary>
        /// <param name="dataInputObject"></param>
        /// <param name="arrBytesSource"></param>
        /// <returns>The MemoryStream object.</returns>
        public Stream FillDataObject(object dataInputObject, byte[] arrBytesSource)
        {
            MemoryStream memoryStream = null;

            try
            {
                if (dataInputObject != null)
                {
                    if (arrBytesSource != null && arrBytesSource.Length > 0)
                    {
                        #region Fix bug TFS #1971
                        //memoryStream = new MemoryStream(arrBytesSource, true);
                        memoryStream = new MemoryStream();
                        memoryStream.Write(arrBytesSource, 0, arrBytesSource.Length);
                        memoryStream.Position = 0;
                        #endregion

                        // Use OpenXML to process
                        var dictionary = GetDictionaryFromObject(dataInputObject);
                        using (WordprocessingDocument word = WordprocessingDocument.Open(memoryStream, true))
                        {
                            var part     = word.MainDocumentPart;
                            var elements = part.Document.Descendants <SdtElement>().ToList();
                            foreach (SdtElement element in elements)
                            {
                                SdtAlias alias = element.Descendants <SdtAlias>().FirstOrDefault();
                                if (alias != null)
                                {
                                    // Get title of content control
                                    var title = alias.Val.Value;
                                    if (dictionary.ContainsKey(title))
                                    {
                                        object value = dictionary[title];

                                        if (value != null)
                                        {
                                            if (element.ToString().Equals("DocumentFormat.OpenXml.Wordprocessing.SdtRun"))
                                            {
                                                SdtRun run = element as SdtRun;
                                                if (run != null)
                                                {
                                                    if (value is bool)
                                                    {
                                                        SdtContentCheckBox contentCheckBox = run.Descendants <SdtContentCheckBox>().FirstOrDefault();
                                                        if (contentCheckBox != null)
                                                        {
                                                            if (string.Compare(value.ToString(), Boolean.TrueString, true) == 0)
                                                            {
                                                                contentCheckBox.Checked.Val = string.Compare(value.ToString(), Boolean.TrueString, true) == 0 ? OnOffValues.One : OnOffValues.Zero;
                                                                SdtContentRun contentRun = run.Descendants <SdtContentRun>().FirstOrDefault();
                                                                if (contentRun != null)
                                                                {
                                                                    Run xRun = contentRun.Descendants <Run>().FirstOrDefault();
                                                                    if (xRun != null)
                                                                    {
                                                                        SymbolChar checkedSymbolChar = xRun.Descendants <SymbolChar>().FirstOrDefault();
                                                                        if (checkedSymbolChar != null)
                                                                        {
                                                                            checkedSymbolChar.Char = new HexBinaryValue(CheckedSymbolChar);
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                    else
                                                    {
                                                        SdtContentRun contentRun = run.Descendants <SdtContentRun>().FirstOrDefault();
                                                        Run           xRun       = contentRun.Descendants <Run>().FirstOrDefault();
                                                        if (xRun == null)
                                                        {
                                                            contentRun.AppendChild(new Run());
                                                            xRun = contentRun.Descendants <Run>().FirstOrDefault();
                                                        }
                                                        Text text = xRun.Descendants <Text>().FirstOrDefault();
                                                        if (text == null)
                                                        {
                                                            xRun.AppendChild(new Text(value.ToString()));
                                                            text = xRun.Descendants <Text>().FirstOrDefault();
                                                        }
                                                        text.Text = value.ToString();
                                                    }
                                                }
                                            }
                                            else if (element.ToString().Equals("DocumentFormat.OpenXml.Wordprocessing.SdtBlock"))
                                            {
                                                SdtBlock block = element as SdtBlock;
                                                if (block != null)
                                                {
                                                    if (value is bool)
                                                    {
                                                        SdtContentCheckBox contentCheckBox = block.Descendants <SdtContentCheckBox>().FirstOrDefault();
                                                        if (contentCheckBox != null)
                                                        {
                                                            if (string.Compare(value.ToString(), Boolean.TrueString, true) == 0)
                                                            {
                                                                contentCheckBox.Checked.Val = string.Compare(value.ToString(), Boolean.TrueString, true) == 0 ? OnOffValues.One : OnOffValues.Zero;
                                                                SdtContentRun contentRun = block.Descendants <SdtContentRun>().FirstOrDefault();
                                                                if (contentRun != null)
                                                                {
                                                                    Run xRun = contentRun.Descendants <Run>().FirstOrDefault();
                                                                    if (xRun != null)
                                                                    {
                                                                        SymbolChar checkedSymbolChar = xRun.Descendants <SymbolChar>().FirstOrDefault();
                                                                        if (checkedSymbolChar != null)
                                                                        {
                                                                            checkedSymbolChar.Char = new HexBinaryValue(CheckedSymbolChar);
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                    else
                                                    {
                                                        SdtContentBlock contentBlock = block.Descendants <SdtContentBlock>().FirstOrDefault();
                                                        Run             xRun         = contentBlock.Descendants <Run>().FirstOrDefault();
                                                        if (xRun == null)
                                                        {
                                                            contentBlock.AppendChild(new Run());
                                                            xRun = contentBlock.Descendants <Run>().FirstOrDefault();
                                                        }
                                                        Text text = xRun.Descendants <Text>().FirstOrDefault();
                                                        if (text == null)
                                                        {
                                                            xRun.AppendChild(new Text(value.ToString()));
                                                            text = xRun.Descendants <Text>().FirstOrDefault();
                                                        }
                                                        text.Text = value.ToString();
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }

                            part.Document.Save();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ULSLogging.LogError(ex);
                throw ex;
            }

            return(memoryStream);
        }
예제 #9
0
        public static TableCell CreateColumnCell(ColumnTable column)
        {
            TableCell tableCell = new TableCell();

            TableCellProperties tableCellProperties = new TableCellProperties();

            DocumentFormat.OpenXml.Wordprocessing.ConditionalFormatStyle conditionalFormatStyleCell1 = new ConditionalFormatStyle()
            {
                Val = "001000000000", FirstRow = false, LastRow = false, FirstColumn = true, LastColumn = false, OddVerticalBand = false, EvenVerticalBand = false, OddHorizontalBand = false, EvenHorizontalBand = false, FirstRowFirstColumn = false, FirstRowLastColumn = false, LastRowFirstColumn = false, LastRowLastColumn = false
            };
            DocumentFormat.OpenXml.Wordprocessing.TableCellWidth tableCellWidth1 = new TableCellWidth()
            {
                Type = TableWidthUnitValues.Dxa
            };

            tableCellProperties.Append(conditionalFormatStyleCell1);
            tableCellProperties.Append(tableCellWidth1);

            SdtBlock sdtBlockSub = new SdtBlock();

            SdtProperties sdtProperties = new SdtProperties();

            RunProperties runProperties = new RunProperties();
            RunFonts      runFonts1     = new RunFonts()
            {
                Ascii = "Times New Roman", HighAnsi = "Times New Roman", ComplexScript = "Times New Roman"
            };
            FontSize fontSize1 = new FontSize()
            {
                Val = "28"
            };
            FontSizeComplexScript fontSizeComplexScript1 = new FontSizeComplexScript()
            {
                Val = "28"
            };

            runProperties.Append(runFonts1);
            runProperties.Append(fontSize1);
            runProperties.Append(fontSizeComplexScript1);
            SdtAlias sdtAliasSub = new SdtAlias()
            {
                Val = column.ColumnField
            };
            Tag tagCell = new Tag()
            {
                Val = column.ColumnField
            };
            SdtId sdtIdCell = new SdtId()
            {
                Val = -2144724967
            };

            SdtPlaceholder   sdtPlaceholderCell1   = new SdtPlaceholder();
            DocPartReference docPartReferenceCell1 = new DocPartReference()
            {
                Val = "941489452D594FF2A513A53EEFA3E58F"
            };

            sdtPlaceholderCell1.Append(docPartReferenceCell1);

            sdtProperties.Append(runProperties);
            sdtProperties.Append(sdtAliasSub);
            sdtProperties.Append(tagCell);
            sdtProperties.Append(sdtIdCell);
            sdtProperties.Append(sdtPlaceholderCell1);

            SdtContentBlock sdtContentBlockSub = new SdtContentBlock();

            Paragraph paragraphCell = new Paragraph()
            {
                RsidParagraphAddition = "00C03259", RsidParagraphProperties = "00BB7EFE", RsidRunAdditionDefault = "00C03259"
            };

            ParagraphProperties paragraphProperties1 = new ParagraphProperties();

            ParagraphMarkRunProperties paragraphMarkRunPropertiesCell = new ParagraphMarkRunProperties();
            RunFonts runFonts2 = new RunFonts()
            {
                Ascii = "Times New Roman", HighAnsi = "Times New Roman", ComplexScript = "Times New Roman"
            };
            FontSize fontSize2 = new FontSize()
            {
                Val = "28"
            };
            FontSizeComplexScript fontSizeComplexScript2 = new FontSizeComplexScript()
            {
                Val = "28"
            };

            paragraphMarkRunPropertiesCell.Append(runFonts2);
            paragraphMarkRunPropertiesCell.Append(fontSize2);
            paragraphMarkRunPropertiesCell.Append(fontSizeComplexScript2);

            paragraphProperties1.Append(paragraphMarkRunPropertiesCell);

            Run runCell = new Run();

            RunProperties runPropertiesCell = new RunProperties();
            RunFonts      runFonts3         = new RunFonts()
            {
                Ascii = "Times New Roman", HighAnsi = "Times New Roman", ComplexScript = "Times New Roman"
            };
            Bold bold1 = new Bold()
            {
                Val = false
            };
            FontSize fontSize3 = new FontSize()
            {
                Val = "28"
            };
            FontSizeComplexScript fontSizeComplexScript3 = new FontSizeComplexScript()
            {
                Val = "28"
            };

            runPropertiesCell.Append(runFonts3);
            runPropertiesCell.Append(bold1);
            runPropertiesCell.Append(fontSize3);
            runPropertiesCell.Append(fontSizeComplexScript3);

            Text textCell = new Text();

            textCell.Text = column.ColumnHeader;

            runCell.Append(runPropertiesCell);
            runCell.Append(textCell);

            paragraphCell.Append(paragraphProperties1);
            paragraphCell.Append(runCell);

            sdtContentBlockSub.Append(paragraphCell);

            sdtBlockSub.Append(sdtProperties);
            sdtBlockSub.Append(sdtContentBlockSub);

            tableCell.Append(tableCellProperties);
            tableCell.Append(sdtBlockSub);
            return(tableCell);
        }
예제 #10
0
        public static SdtRun GetField(string Name)
        {
            SdtRun sdtRun1 = new SdtRun();

            SdtProperties sdtProperties1 = new SdtProperties();
            RunProperties runProperties1 = new RunProperties();
            RunFonts      runFonts2      = new RunFonts()
            {
                Ascii = "Times New Roman", HighAnsi = "Times New Roman", ComplexScript = "Times New Roman"
            };
            FontSize fontSize2 = new FontSize()
            {
                Val = "28"
            };
            FontSizeComplexScript fontSizeComplexScript2 = new FontSizeComplexScript()
            {
                Val = "28"
            };

            runProperties1.Append(runFonts2);
            runProperties1.Append(fontSize2);
            runProperties1.Append(fontSizeComplexScript2);
            SdtAlias sdtAlias1 = new SdtAlias()
            {
                Val = Name
            };
            Tag tag1 = new Tag()
            {
                Val = Name
            };
            SdtId sdtId1 = new SdtId()
            {
                Val = -1033731646
            };

            SdtPlaceholder   sdtPlaceholder1   = new SdtPlaceholder();
            DocPartReference docPartReference1 = new DocPartReference()
            {
                Val = "DefaultPlaceholder_1082065158"
            };

            sdtPlaceholder1.Append(docPartReference1);
            sdtProperties1.Append(runProperties1);
            sdtProperties1.Append(sdtAlias1);
            sdtProperties1.Append(tag1);
            sdtProperties1.Append(sdtId1);
            sdtProperties1.Append(sdtPlaceholder1);
            SdtEndCharProperties sdtEndCharProperties1 = new SdtEndCharProperties();

            SdtContentRun sdtContentRun1 = new SdtContentRun();

            Run           run1           = new Run();
            RunProperties runProperties2 = new RunProperties();
            RunFonts      runFonts3      = new RunFonts()
            {
                Ascii = "Times New Roman", HighAnsi = "Times New Roman", ComplexScript = "Times New Roman"
            };
            FontSize fontSize3 = new FontSize()
            {
                Val = "28"
            };
            FontSizeComplexScript fontSizeComplexScript3 = new FontSizeComplexScript()
            {
                Val = "28"
            };

            runProperties2.Append(runFonts3);
            runProperties2.Append(fontSize3);
            runProperties2.Append(fontSizeComplexScript3);

            Text text1 = new Text();

            text1.Text = Name;

            run1.Append(runProperties2);
            run1.Append(text1);

            sdtContentRun1.Append(run1);

            sdtRun1.Append(sdtProperties1);
            sdtRun1.Append(sdtEndCharProperties1);
            sdtRun1.Append(sdtContentRun1);

            return(sdtRun1);
        }
예제 #11
0
        public static SdtBlock CreateTable(List <ColumnTable> columns, string tableName)
        {
            SdtBlock sdtBlock1 = new SdtBlock();

            SdtProperties sdtProperties1 = new SdtProperties();

            RunProperties runProperties1 = new RunProperties();
            Bold          bold1          = new Bold()
            {
                Val = false
            };
            BoldComplexScript boldComplexScript1 = new BoldComplexScript()
            {
                Val = false
            };
            Color color1 = new Color()
            {
                Val = "auto"
            };
            Languages languages1 = new Languages()
            {
                Val = "en-US"
            };

            runProperties1.Append(bold1);
            runProperties1.Append(boldComplexScript1);
            runProperties1.Append(color1);
            runProperties1.Append(languages1);
            SdtAlias sdtAlias1 = new SdtAlias()
            {
                Val = tableName
            };
            Tag tag1 = new Tag()
            {
                Val = tableName
            };
            SdtId sdtId1 = new SdtId()
            {
                Val = -1702077049
            };

            SdtPlaceholder   sdtPlaceholder1   = new SdtPlaceholder();
            DocPartReference docPartReference1 = new DocPartReference()
            {
                Val = "DefaultPlaceholder_1081868574"
            };

            sdtPlaceholder1.Append(docPartReference1);

            sdtProperties1.Append(runProperties1);
            sdtProperties1.Append(sdtAlias1);
            sdtProperties1.Append(tag1);
            sdtProperties1.Append(sdtId1);
            sdtProperties1.Append(sdtPlaceholder1);
            SdtEndCharProperties sdtEndCharProperties1 = new SdtEndCharProperties();

            SdtContentBlock sdtContentBlock1 = new SdtContentBlock();

            Table table1 = new Table();

            TableProperties tableProperties1 = new TableProperties();

            TableStyle tableStyle1 = new TableStyle()
            {
                Val = "GridTable4-Accent1"
            };
            TableWidth tableWidth1 = new TableWidth()
            {
                Width = "0", Type = TableWidthUnitValues.Auto
            };

            TableBorders tableBorders1 = new TableBorders();
            TopBorder    topBorder1    = new TopBorder()
            {
                Val = BorderValues.Single, Color = "auto", Size = (UInt32Value)4U, Space = (UInt32Value)0U
            };
            LeftBorder leftBorder1 = new LeftBorder()
            {
                Val = BorderValues.Single, Color = "auto", Size = (UInt32Value)4U, Space = (UInt32Value)0U
            };
            BottomBorder bottomBorder1 = new BottomBorder()
            {
                Val = BorderValues.Single, Color = "auto", Size = (UInt32Value)4U, Space = (UInt32Value)0U
            };
            RightBorder rightBorder1 = new RightBorder()
            {
                Val = BorderValues.Single, Color = "auto", Size = (UInt32Value)4U, Space = (UInt32Value)0U
            };
            InsideHorizontalBorder insideHorizontalBorder1 = new InsideHorizontalBorder()
            {
                Val = BorderValues.Single, Color = "auto", Size = (UInt32Value)4U, Space = (UInt32Value)0U
            };
            InsideVerticalBorder insideVerticalBorder1 = new InsideVerticalBorder()
            {
                Val = BorderValues.Single, Color = "auto", Size = (UInt32Value)4U, Space = (UInt32Value)0U
            };

            tableBorders1.Append(topBorder1);
            tableBorders1.Append(leftBorder1);
            tableBorders1.Append(bottomBorder1);
            tableBorders1.Append(rightBorder1);
            tableBorders1.Append(insideHorizontalBorder1);
            tableBorders1.Append(insideVerticalBorder1);

            TableCellMarginDefault tableCellMarginDefault1 = new TableCellMarginDefault();
            TableCellLeftMargin    tableCellLeftMargin1    = new TableCellLeftMargin()
            {
                Width = 10, Type = TableWidthValues.Dxa
            };
            TableCellRightMargin tableCellRightMargin1 = new TableCellRightMargin()
            {
                Width = 10, Type = TableWidthValues.Dxa
            };

            tableCellMarginDefault1.Append(tableCellLeftMargin1);
            tableCellMarginDefault1.Append(tableCellRightMargin1);

            TableLook tableLook1 = new TableLook()
            {
                Val = "04A0", FirstRow = true, LastRow = false, FirstColumn = true, LastColumn = false, NoHorizontalBand = false, NoVerticalBand = true
            };

            tableProperties1.Append(tableCellMarginDefault1);
            tableProperties1.Append(tableBorders1);
            tableProperties1.Append(tableStyle1);
            tableProperties1.Append(tableWidth1);
            tableProperties1.Append(tableLook1);

            TableGrid tableGrid1 = new TableGrid();

            foreach (ColumnTable column in columns)
            {
                GridColumn gridColumn1 = new GridColumn()
                {
                };
                tableGrid1.Append(gridColumn1);
            }
            TableRow tableRow1 = CreateHeaderRow(columns);
            TableRow tableRow2 = CreateCellRow(columns);

            table1.Append(tableProperties1);
            table1.Append(tableGrid1);
            table1.Append(tableRow1);
            table1.Append(tableRow2);

            sdtContentBlock1.Append(table1);

            sdtBlock1.Append(sdtProperties1);
            sdtBlock1.Append(sdtEndCharProperties1);
            sdtBlock1.Append(sdtContentBlock1);
            return(sdtBlock1);
        }
예제 #12
0
        public void wordDocOpenXml(string TemplateFileLocation, string GeneratedFileNameLocation, List <ModelField> dataMap)
        {
            if (System.IO.File.Exists(GeneratedFileNameLocation))
            {
                System.IO.File.Delete(GeneratedFileNameLocation);
            }

            System.IO.File.Copy(TemplateFileLocation, GeneratedFileNameLocation);

            using (WordprocessingDocument document = WordprocessingDocument.Open(GeneratedFileNameLocation, true))
            {
                // Change the document type to Document
                document.ChangeDocumentType(DocumentFormat.OpenXml.WordprocessingDocumentType.Document);

                // Get the MainPart of the document
                MainDocumentPart mainPart = document.MainDocumentPart;

                // Get the Document Settings Part
                DocumentSettingsPart documentSettingPart1 = mainPart.DocumentSettingsPart;

                OpenXmlElement[] Enumerate = mainPart.ContentControls().ToArray();

                for (int i = 0; i < Enumerate.Count(); i++)
                {
                    OpenXmlElement cc    = Enumerate[i];
                    SdtProperties  props = cc.Elements <SdtProperties>().FirstOrDefault();
                    Tag            tag   = props.Elements <Tag>().FirstOrDefault();
                    //Console.WriteLine(tag.Val);
                    SdtAlias alias   = props.Elements <SdtAlias>().FirstOrDefault();
                    string   title   = ((DocumentFormat.OpenXml.Wordprocessing.StringType)(alias)).Val;
                    string   tagName = tag.Val;

                    //if (dataMap.Any(f => string.Format("{0}Tag", f.Key) == tagName))
                    if (dataMap.Any(f => f.Key == title))
                    {
                        var    valkey = dataMap.FirstOrDefault(f => f.Key == title).Value;
                        object val    = POCUtil.DictionaryMappedDocPOC[valkey];

                        OpenXmlElement parentElement = cc.Parent;


                        DocumentFormat.OpenXml.Wordprocessing.Paragraph pg = cc.Descendants <DocumentFormat.OpenXml.Wordprocessing.Paragraph>().FirstOrDefault();
                        if (pg != null || true)
                        {
                            //ParagraphProperties paragraphProperties = (ParagraphProperties)cc.Descendants<DocumentFormat.OpenXml.Wordprocessing.Paragraph>().FirstOrDefault().ParagraphProperties.Clone();

                            Run r1 = null;
                            DocumentFormat.OpenXml.Wordprocessing.Paragraph p1 = null;

                            if (cc.Parent.GetType() != typeof(DocumentFormat.OpenXml.Wordprocessing.Paragraph))
                            {
                                p1 = parentElement.InsertAfter(new DocumentFormat.OpenXml.Wordprocessing.Paragraph(), cc);
                                r1 = p1.AppendChild(new Run());
                            }
                            else
                            {
                                r1 = parentElement.InsertAfter(new Run(), cc);
                            }

                            r1.RunProperties = new RunProperties();

                            cc.Descendants <DocumentFormat.OpenXml.Wordprocessing.RunProperties>().ToList().ForEach(
                                runProperty => runProperty.ToList().ForEach(
                                    property =>
                            {
                                if (!r1.RunProperties.ChildElements.ToList().Exists(propertyToAdd => propertyToAdd.GetType() == property.GetType()))
                                {
                                    r1.RunProperties.AppendChild((OpenXmlElement)property.CloneNode(true));
                                }
                            }
                                    )
                                );

                            if (cc.Descendants <DocumentFormat.OpenXml.Office2010.Word.SdtContentCheckBox>().Count() > 0)
                            {
                                //☒
                                //☐
                                //☐
                                var t2 = r1.AppendChild(new Text("☒"));
                                //DocumentFormat.OpenXml.Wordprocessing.CheckBox c1 = r1.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.CheckBox());
                                //c1.AppendChild(new Checked());
                            }
                            else
                            {
                                var t1 = r1.AppendChild(new Text(val.ToString()));
                            }
                        }
                    }
                }


                while (mainPart.ContentControls().Count() > 0)
                {
                    mainPart.ContentControls().FirstOrDefault().Remove();
                }

                // Save the document
                mainPart.Document.Save();
                document.Close();
            }
        }
        public void Execute()
        {
            SdtElement repeat_sql_cc = content_control.Descendants <SdtElement>().Where(s => s.Descendants <SdtAlias>().FirstOrDefault().Val.ToString().ToLower() == StaticValues.repeatsql_cc_name).FirstOrDefault();

            sql_query = GetContentControlContents(repeat_sql_cc);
            if (!StaticValues.use_default_tablename_in_sql)
            {
                sql_query = sql_query.Replace(StaticValues.dummy_table_name, StaticValues.project_table_name);
            }
            DataTable result = GetDataFromDatabaseUsingSQL();

            for (int i = 0; i < result.Rows.Count - 1; i++)
            {
                CloneData();
            }

            List <string> columnNames = (from dc in result.Columns.Cast <DataColumn>()
                                         select dc.ColumnName.ToLower()).ToList();

            WordTemplateManager sub_manager;
            int row_count = 0;

            foreach (SdtElement repeated_cc in content_control.Descendants <SdtElement>().Where(s => s.Descendants <SdtAlias>().FirstOrDefault().Val.ToString().ToLower() == StaticValues.repeatcontent_cc_name))
            {
                foreach (SdtElement nested_cc in repeated_cc.Descendants <SdtElement>())
                {
                    SdtAlias alias = nested_cc.Descendants <SdtAlias>().FirstOrDefault();
                    if (alias.Val.ToString().ToLower() == StaticValues.repeatval_cc_name)
                    {
                        string sql_content = GetContentControlContents(nested_cc);

                        string append_data = "";
                        // If the content sql specify the data from the above sql
                        if (columnNames.Contains(sql_content.ToLower()))
                        {
                            append_data = result.Rows[row_count][sql_content.ToLower()].ToString();
                        }
                        else
                        {
                            // If the content sql specify a query
                            if (!StaticValues.use_default_tablename_in_sql)
                            {
                                sql_content = sql_content.Replace(StaticValues.dummy_table_name, StaticValues.project_table_name);
                            }

                            DataRow conditional = result.Rows[row_count];
                            sql_content = Helper_WordBase.AddCondtionalToSQLQuery(sql_content, conditional);

                            DataTable selectvalue_result = GetDataFromDatabaseUsingSQL(sql_content);
                            if (selectvalue_result != null)
                            {
                                // TODO: Print out more values if possible
                                // Only print the 1st value found
                                append_data = selectvalue_result.Rows[0][0].ToString();
                            }
                        }
                        ReplaceContentsInContentControl(nested_cc, append_data);
                    }
                    else
                    {
                        DataRow conditional = result.Rows[row_count];
                        sub_manager = new WordTemplateManager(nested_cc);
                        sub_manager.Process(conditional);
                    }
                }
                row_count++;
            }
        }
        // Generates content of mainDocumentPart1.
        private void GenerateMainDocumentPart1Content(MainDocumentPart mainDocumentPart1)
        {
            Document document1 = new Document();
            document1.AddNamespaceDeclaration("ve", "http://schemas.openxmlformats.org/markup-compatibility/2006");
            document1.AddNamespaceDeclaration("o", "urn:schemas-microsoft-com:office:office");
            document1.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
            document1.AddNamespaceDeclaration("m", "http://schemas.openxmlformats.org/officeDocument/2006/math");
            document1.AddNamespaceDeclaration("v", "urn:schemas-microsoft-com:vml");
            document1.AddNamespaceDeclaration("wp", "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing");
            document1.AddNamespaceDeclaration("w10", "urn:schemas-microsoft-com:office:word");
            document1.AddNamespaceDeclaration("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main");
            document1.AddNamespaceDeclaration("wne", "http://schemas.microsoft.com/office/word/2006/wordml");

            Body body1 = new Body();

            Paragraph paragraph1 = new Paragraph() { RsidParagraphAddition = "006E2549", RsidRunAdditionDefault = "00E850CC" };

            Run run1 = new Run();
            Text text1 = new Text();
            text1.Text = "This document contains content controls that will be bound to a custom XML part.";

            run1.Append(text1);

            paragraph1.Append(run1);
            Paragraph paragraph2 = new Paragraph() { RsidParagraphAddition = "00E850CC", RsidRunAdditionDefault = "00E850CC" };

            Table table1 = new Table();

            TableProperties tableProperties1 = new TableProperties();
            TableStyle tableStyle1 = new TableStyle() { Val = "TableGrid" };
            TableWidth tableWidth1 = new TableWidth() { Width = "0", Type = TableWidthUnitValues.Auto };
            TableLook tableLook1 = new TableLook() { Val = "04A0" };

            tableProperties1.Append(tableStyle1);
            tableProperties1.Append(tableWidth1);
            tableProperties1.Append(tableLook1);

            TableGrid tableGrid1 = new TableGrid();
            GridColumn gridColumn1 = new GridColumn() { Width = "1908" };
            GridColumn gridColumn2 = new GridColumn() { Width = "4410" };

            tableGrid1.Append(gridColumn1);
            tableGrid1.Append(gridColumn2);

            TableRow tableRow1 = new TableRow() { RsidTableRowAddition = "00E850CC", RsidTableRowProperties = "00E850CC" };

            TableCell tableCell1 = new TableCell();

            TableCellProperties tableCellProperties1 = new TableCellProperties();
            TableCellWidth tableCellWidth1 = new TableCellWidth() { Width = "1908", Type = TableWidthUnitValues.Dxa };

            tableCellProperties1.Append(tableCellWidth1);

            Paragraph paragraph3 = new Paragraph() { RsidParagraphAddition = "00E850CC", RsidRunAdditionDefault = "00E850CC" };

            Run run2 = new Run();
            Text text2 = new Text();
            text2.Text = "Name";

            run2.Append(text2);

            paragraph3.Append(run2);

            tableCell1.Append(tableCellProperties1);
            tableCell1.Append(paragraph3);

            SdtCell sdtCell1 = new SdtCell();

            SdtProperties sdtProperties1 = new SdtProperties();
            SdtAlias sdtAlias1 = new SdtAlias() { Val = "Name" };
            Tag tag1 = new Tag() { Val = "Name" };
            SdtId sdtId1 = new SdtId() { Val = 13264407 };

            SdtPlaceholder sdtPlaceholder1 = new SdtPlaceholder();
            DocPartReference docPartReference1 = new DocPartReference() { Val = "DefaultPlaceholder_22675703" };

            sdtPlaceholder1.Append(docPartReference1);
            DataBinding dataBinding1 = new DataBinding() { XPath = "/Root/Name", StoreItemId = "{7776B924-6173-4963-94EF-05AF7A57A4C4}" };
            SdtContentText sdtContentText1 = new SdtContentText();

            sdtProperties1.Append(sdtAlias1);
            sdtProperties1.Append(tag1);
            sdtProperties1.Append(sdtId1);
            sdtProperties1.Append(sdtPlaceholder1);
            sdtProperties1.Append(dataBinding1);
            sdtProperties1.Append(sdtContentText1);

            SdtContentCell sdtContentCell1 = new SdtContentCell();

            TableCell tableCell2 = new TableCell();

            TableCellProperties tableCellProperties2 = new TableCellProperties();
            TableCellWidth tableCellWidth2 = new TableCellWidth() { Width = "4410", Type = TableWidthUnitValues.Dxa };

            tableCellProperties2.Append(tableCellWidth2);

            Paragraph paragraph4 = new Paragraph() { RsidParagraphAddition = "00E850CC", RsidParagraphProperties = "00E850CC", RsidRunAdditionDefault = "00A539C5" };

            Run run3 = new Run();
            Text text3 = new Text();
            text3.Text = "Eric White";

            run3.Append(text3);

            paragraph4.Append(run3);

            tableCell2.Append(tableCellProperties2);
            tableCell2.Append(paragraph4);

            sdtContentCell1.Append(tableCell2);

            sdtCell1.Append(sdtProperties1);
            sdtCell1.Append(sdtContentCell1);

            tableRow1.Append(tableCell1);
            tableRow1.Append(sdtCell1);

            TableRow tableRow2 = new TableRow() { RsidTableRowAddition = "00E850CC", RsidTableRowProperties = "00E850CC" };

            TableCell tableCell3 = new TableCell();

            TableCellProperties tableCellProperties3 = new TableCellProperties();
            TableCellWidth tableCellWidth3 = new TableCellWidth() { Width = "1908", Type = TableWidthUnitValues.Dxa };

            tableCellProperties3.Append(tableCellWidth3);

            Paragraph paragraph5 = new Paragraph() { RsidParagraphAddition = "00E850CC", RsidRunAdditionDefault = "00E850CC" };

            Run run4 = new Run();
            Text text4 = new Text();
            text4.Text = "Company";

            run4.Append(text4);

            paragraph5.Append(run4);

            tableCell3.Append(tableCellProperties3);
            tableCell3.Append(paragraph5);

            TableCell tableCell4 = new TableCell();

            TableCellProperties tableCellProperties4 = new TableCellProperties();
            TableCellWidth tableCellWidth4 = new TableCellWidth() { Width = "4410", Type = TableWidthUnitValues.Dxa };

            tableCellProperties4.Append(tableCellWidth4);

            SdtBlock sdtBlock1 = new SdtBlock();

            SdtProperties sdtProperties2 = new SdtProperties();
            SdtAlias sdtAlias2 = new SdtAlias() { Val = "Company" };
            Tag tag2 = new Tag() { Val = "Company" };
            SdtId sdtId2 = new SdtId() { Val = 13264410 };

            SdtPlaceholder sdtPlaceholder2 = new SdtPlaceholder();
            DocPartReference docPartReference2 = new DocPartReference() { Val = "DefaultPlaceholder_22675703" };

            sdtPlaceholder2.Append(docPartReference2);
            DataBinding dataBinding2 = new DataBinding() { XPath = "/Root/Company", StoreItemId = "{7776B924-6173-4963-94EF-05AF7A57A4C4}" };

            sdtProperties2.Append(sdtAlias2);
            sdtProperties2.Append(tag2);
            sdtProperties2.Append(sdtId2);
            sdtProperties2.Append(sdtPlaceholder2);
            sdtProperties2.Append(dataBinding2);

            SdtContentBlock sdtContentBlock1 = new SdtContentBlock();

            Paragraph paragraph6 = new Paragraph() { RsidParagraphAddition = "00E850CC", RsidRunAdditionDefault = "00E850CC" };

            Run run5 = new Run();
            Text text5 = new Text();
            text5.Text = "Microsoft Corporation";

            run5.Append(text5);

            paragraph6.Append(run5);

            sdtContentBlock1.Append(paragraph6);

            sdtBlock1.Append(sdtProperties2);
            sdtBlock1.Append(sdtContentBlock1);

            tableCell4.Append(tableCellProperties4);
            tableCell4.Append(sdtBlock1);

            tableRow2.Append(tableCell3);
            tableRow2.Append(tableCell4);

            TableRow tableRow3 = new TableRow() { RsidTableRowAddition = "00E850CC", RsidTableRowProperties = "00E850CC" };

            TableCell tableCell5 = new TableCell();

            TableCellProperties tableCellProperties5 = new TableCellProperties();
            TableCellWidth tableCellWidth5 = new TableCellWidth() { Width = "1908", Type = TableWidthUnitValues.Dxa };

            tableCellProperties5.Append(tableCellWidth5);

            Paragraph paragraph7 = new Paragraph() { RsidParagraphAddition = "00E850CC", RsidRunAdditionDefault = "00E850CC" };

            Run run6 = new Run();
            Text text6 = new Text();
            text6.Text = "Address";

            run6.Append(text6);

            paragraph7.Append(run6);

            tableCell5.Append(tableCellProperties5);
            tableCell5.Append(paragraph7);

            TableCell tableCell6 = new TableCell();

            TableCellProperties tableCellProperties6 = new TableCellProperties();
            TableCellWidth tableCellWidth6 = new TableCellWidth() { Width = "4410", Type = TableWidthUnitValues.Dxa };

            tableCellProperties6.Append(tableCellWidth6);

            SdtBlock sdtBlock2 = new SdtBlock();

            SdtProperties sdtProperties3 = new SdtProperties();
            SdtAlias sdtAlias3 = new SdtAlias() { Val = "Address" };
            Tag tag3 = new Tag() { Val = "Address" };
            SdtId sdtId3 = new SdtId() { Val = 13264411 };

            SdtPlaceholder sdtPlaceholder3 = new SdtPlaceholder();
            DocPartReference docPartReference3 = new DocPartReference() { Val = "DefaultPlaceholder_22675703" };

            sdtPlaceholder3.Append(docPartReference3);
            DataBinding dataBinding3 = new DataBinding() { XPath = "/Root/Address", StoreItemId = "{7776B924-6173-4963-94EF-05AF7A57A4C4}" };
            SdtContentText sdtContentText2 = new SdtContentText();

            sdtProperties3.Append(sdtAlias3);
            sdtProperties3.Append(tag3);
            sdtProperties3.Append(sdtId3);
            sdtProperties3.Append(sdtPlaceholder3);
            sdtProperties3.Append(dataBinding3);
            sdtProperties3.Append(sdtContentText2);

            SdtContentBlock sdtContentBlock2 = new SdtContentBlock();

            Paragraph paragraph8 = new Paragraph() { RsidParagraphAddition = "00E850CC", RsidRunAdditionDefault = "00E850CC" };

            Run run7 = new Run();
            Text text7 = new Text();
            text7.Text = "One Microsoft Way";

            run7.Append(text7);

            paragraph8.Append(run7);

            sdtContentBlock2.Append(paragraph8);

            sdtBlock2.Append(sdtProperties3);
            sdtBlock2.Append(sdtContentBlock2);

            tableCell6.Append(tableCellProperties6);
            tableCell6.Append(sdtBlock2);

            tableRow3.Append(tableCell5);
            tableRow3.Append(tableCell6);

            TableRow tableRow4 = new TableRow() { RsidTableRowAddition = "00E850CC", RsidTableRowProperties = "00E850CC" };

            TableCell tableCell7 = new TableCell();

            TableCellProperties tableCellProperties7 = new TableCellProperties();
            TableCellWidth tableCellWidth7 = new TableCellWidth() { Width = "1908", Type = TableWidthUnitValues.Dxa };

            tableCellProperties7.Append(tableCellWidth7);

            Paragraph paragraph9 = new Paragraph() { RsidParagraphAddition = "00E850CC", RsidRunAdditionDefault = "00E850CC" };

            Run run8 = new Run();
            Text text8 = new Text();
            text8.Text = "City";

            run8.Append(text8);

            paragraph9.Append(run8);

            tableCell7.Append(tableCellProperties7);
            tableCell7.Append(paragraph9);

            TableCell tableCell8 = new TableCell();

            TableCellProperties tableCellProperties8 = new TableCellProperties();
            TableCellWidth tableCellWidth8 = new TableCellWidth() { Width = "4410", Type = TableWidthUnitValues.Dxa };

            tableCellProperties8.Append(tableCellWidth8);

            SdtBlock sdtBlock3 = new SdtBlock();

            SdtProperties sdtProperties4 = new SdtProperties();
            SdtAlias sdtAlias4 = new SdtAlias() { Val = "City" };
            Tag tag4 = new Tag() { Val = "City" };
            SdtId sdtId4 = new SdtId() { Val = 13264412 };

            SdtPlaceholder sdtPlaceholder4 = new SdtPlaceholder();
            DocPartReference docPartReference4 = new DocPartReference() { Val = "DefaultPlaceholder_22675703" };

            sdtPlaceholder4.Append(docPartReference4);
            DataBinding dataBinding4 = new DataBinding() { XPath = "/Root/City", StoreItemId = "{7776B924-6173-4963-94EF-05AF7A57A4C4}" };
            SdtContentText sdtContentText3 = new SdtContentText();

            sdtProperties4.Append(sdtAlias4);
            sdtProperties4.Append(tag4);
            sdtProperties4.Append(sdtId4);
            sdtProperties4.Append(sdtPlaceholder4);
            sdtProperties4.Append(dataBinding4);
            sdtProperties4.Append(sdtContentText3);

            SdtContentBlock sdtContentBlock3 = new SdtContentBlock();

            Paragraph paragraph10 = new Paragraph() { RsidParagraphAddition = "00E850CC", RsidRunAdditionDefault = "00E850CC" };

            Run run9 = new Run();
            Text text9 = new Text();
            text9.Text = "Redmond";

            run9.Append(text9);

            paragraph10.Append(run9);

            sdtContentBlock3.Append(paragraph10);

            sdtBlock3.Append(sdtProperties4);
            sdtBlock3.Append(sdtContentBlock3);

            tableCell8.Append(tableCellProperties8);
            tableCell8.Append(sdtBlock3);

            tableRow4.Append(tableCell7);
            tableRow4.Append(tableCell8);

            TableRow tableRow5 = new TableRow() { RsidTableRowAddition = "00E850CC", RsidTableRowProperties = "00E850CC" };

            TableCell tableCell9 = new TableCell();

            TableCellProperties tableCellProperties9 = new TableCellProperties();
            TableCellWidth tableCellWidth9 = new TableCellWidth() { Width = "1908", Type = TableWidthUnitValues.Dxa };

            tableCellProperties9.Append(tableCellWidth9);

            Paragraph paragraph11 = new Paragraph() { RsidParagraphAddition = "00E850CC", RsidRunAdditionDefault = "00E850CC" };

            Run run10 = new Run();
            Text text10 = new Text();
            text10.Text = "State";

            run10.Append(text10);

            paragraph11.Append(run10);

            tableCell9.Append(tableCellProperties9);
            tableCell9.Append(paragraph11);

            TableCell tableCell10 = new TableCell();

            TableCellProperties tableCellProperties10 = new TableCellProperties();
            TableCellWidth tableCellWidth10 = new TableCellWidth() { Width = "4410", Type = TableWidthUnitValues.Dxa };

            tableCellProperties10.Append(tableCellWidth10);

            SdtBlock sdtBlock4 = new SdtBlock();

            SdtProperties sdtProperties5 = new SdtProperties();
            SdtAlias sdtAlias5 = new SdtAlias() { Val = "State" };
            Tag tag5 = new Tag() { Val = "State" };
            SdtId sdtId5 = new SdtId() { Val = 13264413 };

            SdtPlaceholder sdtPlaceholder5 = new SdtPlaceholder();
            DocPartReference docPartReference5 = new DocPartReference() { Val = "DefaultPlaceholder_22675703" };

            sdtPlaceholder5.Append(docPartReference5);
            DataBinding dataBinding5 = new DataBinding() { XPath = "/Root/State", StoreItemId = "{7776B924-6173-4963-94EF-05AF7A57A4C4}" };
            SdtContentText sdtContentText4 = new SdtContentText();

            sdtProperties5.Append(sdtAlias5);
            sdtProperties5.Append(tag5);
            sdtProperties5.Append(sdtId5);
            sdtProperties5.Append(sdtPlaceholder5);
            sdtProperties5.Append(dataBinding5);
            sdtProperties5.Append(sdtContentText4);

            SdtContentBlock sdtContentBlock4 = new SdtContentBlock();

            Paragraph paragraph12 = new Paragraph() { RsidParagraphAddition = "00E850CC", RsidRunAdditionDefault = "00E850CC" };

            Run run11 = new Run();
            Text text11 = new Text();
            text11.Text = "WA";

            run11.Append(text11);

            paragraph12.Append(run11);

            sdtContentBlock4.Append(paragraph12);

            sdtBlock4.Append(sdtProperties5);
            sdtBlock4.Append(sdtContentBlock4);

            tableCell10.Append(tableCellProperties10);
            tableCell10.Append(sdtBlock4);

            tableRow5.Append(tableCell9);
            tableRow5.Append(tableCell10);

            TableRow tableRow6 = new TableRow() { RsidTableRowAddition = "00E850CC", RsidTableRowProperties = "00E850CC" };

            TableCell tableCell11 = new TableCell();

            TableCellProperties tableCellProperties11 = new TableCellProperties();
            TableCellWidth tableCellWidth11 = new TableCellWidth() { Width = "1908", Type = TableWidthUnitValues.Dxa };

            tableCellProperties11.Append(tableCellWidth11);

            Paragraph paragraph13 = new Paragraph() { RsidParagraphAddition = "00E850CC", RsidRunAdditionDefault = "00E850CC" };

            Run run12 = new Run();
            Text text12 = new Text();
            text12.Text = "Country";

            run12.Append(text12);

            paragraph13.Append(run12);

            tableCell11.Append(tableCellProperties11);
            tableCell11.Append(paragraph13);

            TableCell tableCell12 = new TableCell();

            TableCellProperties tableCellProperties12 = new TableCellProperties();
            TableCellWidth tableCellWidth12 = new TableCellWidth() { Width = "4410", Type = TableWidthUnitValues.Dxa };

            tableCellProperties12.Append(tableCellWidth12);

            SdtBlock sdtBlock5 = new SdtBlock();

            SdtProperties sdtProperties6 = new SdtProperties();
            SdtAlias sdtAlias6 = new SdtAlias() { Val = "Country" };
            Tag tag6 = new Tag() { Val = "Country" };
            SdtId sdtId6 = new SdtId() { Val = 13264414 };

            SdtPlaceholder sdtPlaceholder6 = new SdtPlaceholder();
            DocPartReference docPartReference6 = new DocPartReference() { Val = "DefaultPlaceholder_22675703" };

            sdtPlaceholder6.Append(docPartReference6);
            DataBinding dataBinding6 = new DataBinding() { XPath = "/Root/Country", StoreItemId = "{7776B924-6173-4963-94EF-05AF7A57A4C4}" };
            SdtContentText sdtContentText5 = new SdtContentText();

            sdtProperties6.Append(sdtAlias6);
            sdtProperties6.Append(tag6);
            sdtProperties6.Append(sdtId6);
            sdtProperties6.Append(sdtPlaceholder6);
            sdtProperties6.Append(dataBinding6);
            sdtProperties6.Append(sdtContentText5);

            SdtContentBlock sdtContentBlock5 = new SdtContentBlock();

            Paragraph paragraph14 = new Paragraph() { RsidParagraphAddition = "00E850CC", RsidRunAdditionDefault = "00E850CC" };

            Run run13 = new Run();
            Text text13 = new Text();
            text13.Text = "USA";

            run13.Append(text13);

            paragraph14.Append(run13);

            sdtContentBlock5.Append(paragraph14);

            sdtBlock5.Append(sdtProperties6);
            sdtBlock5.Append(sdtContentBlock5);

            tableCell12.Append(tableCellProperties12);
            tableCell12.Append(sdtBlock5);

            tableRow6.Append(tableCell11);
            tableRow6.Append(tableCell12);

            TableRow tableRow7 = new TableRow() { RsidTableRowAddition = "00E850CC", RsidTableRowProperties = "00E850CC" };

            TableRowProperties tableRowProperties1 = new TableRowProperties();
            TableRowHeight tableRowHeight1 = new TableRowHeight() { Val = (UInt32Value)188U };

            tableRowProperties1.Append(tableRowHeight1);

            TableCell tableCell13 = new TableCell();

            TableCellProperties tableCellProperties13 = new TableCellProperties();
            TableCellWidth tableCellWidth13 = new TableCellWidth() { Width = "1908", Type = TableWidthUnitValues.Dxa };

            tableCellProperties13.Append(tableCellWidth13);

            Paragraph paragraph15 = new Paragraph() { RsidParagraphAddition = "00E850CC", RsidRunAdditionDefault = "00E850CC" };

            Run run14 = new Run();
            Text text14 = new Text();
            text14.Text = "Postal Code";

            run14.Append(text14);

            paragraph15.Append(run14);

            tableCell13.Append(tableCellProperties13);
            tableCell13.Append(paragraph15);

            TableCell tableCell14 = new TableCell();

            TableCellProperties tableCellProperties14 = new TableCellProperties();
            TableCellWidth tableCellWidth14 = new TableCellWidth() { Width = "4410", Type = TableWidthUnitValues.Dxa };

            tableCellProperties14.Append(tableCellWidth14);

            SdtBlock sdtBlock6 = new SdtBlock();

            SdtProperties sdtProperties7 = new SdtProperties();
            SdtAlias sdtAlias7 = new SdtAlias() { Val = "PostalCode" };
            Tag tag7 = new Tag() { Val = "PostalCode" };
            SdtId sdtId7 = new SdtId() { Val = 13264415 };

            SdtPlaceholder sdtPlaceholder7 = new SdtPlaceholder();
            DocPartReference docPartReference7 = new DocPartReference() { Val = "DefaultPlaceholder_22675703" };

            sdtPlaceholder7.Append(docPartReference7);
            DataBinding dataBinding7 = new DataBinding() { XPath = "/Root/PostalCode", StoreItemId = "{7776B924-6173-4963-94EF-05AF7A57A4C4}" };
            SdtContentText sdtContentText6 = new SdtContentText();

            sdtProperties7.Append(sdtAlias7);
            sdtProperties7.Append(tag7);
            sdtProperties7.Append(sdtId7);
            sdtProperties7.Append(sdtPlaceholder7);
            sdtProperties7.Append(dataBinding7);
            sdtProperties7.Append(sdtContentText6);

            SdtContentBlock sdtContentBlock6 = new SdtContentBlock();

            Paragraph paragraph16 = new Paragraph() { RsidParagraphAddition = "00E850CC", RsidRunAdditionDefault = "00E850CC" };

            Run run15 = new Run();
            Text text15 = new Text();
            text15.Text = "98052";

            run15.Append(text15);

            paragraph16.Append(run15);

            sdtContentBlock6.Append(paragraph16);

            sdtBlock6.Append(sdtProperties7);
            sdtBlock6.Append(sdtContentBlock6);

            tableCell14.Append(tableCellProperties14);
            tableCell14.Append(sdtBlock6);

            tableRow7.Append(tableRowProperties1);
            tableRow7.Append(tableCell13);
            tableRow7.Append(tableCell14);

            table1.Append(tableProperties1);
            table1.Append(tableGrid1);
            table1.Append(tableRow1);
            table1.Append(tableRow2);
            table1.Append(tableRow3);
            table1.Append(tableRow4);
            table1.Append(tableRow5);
            table1.Append(tableRow6);
            table1.Append(tableRow7);
            Paragraph paragraph17 = new Paragraph() { RsidParagraphAddition = "00E850CC", RsidRunAdditionDefault = "00E850CC" };

            SectionProperties sectionProperties1 = new SectionProperties() { RsidR = "00E850CC", RsidSect = "006E2549" };
            PageSize pageSize1 = new PageSize() { Width = (UInt32Value)12240U, Height = (UInt32Value)15840U };
            PageMargin pageMargin1 = new PageMargin() { Top = 1440, Right = (UInt32Value)1440U, Bottom = 1440, Left = (UInt32Value)1440U, Header = (UInt32Value)720U, Footer = (UInt32Value)720U, Gutter = (UInt32Value)0U };
            Columns columns1 = new Columns() { Space = "720" };
            DocGrid docGrid1 = new DocGrid() { LinePitch = 360 };

            sectionProperties1.Append(pageSize1);
            sectionProperties1.Append(pageMargin1);
            sectionProperties1.Append(columns1);
            sectionProperties1.Append(docGrid1);

            body1.Append(paragraph1);
            body1.Append(paragraph2);
            body1.Append(table1);
            body1.Append(paragraph17);
            body1.Append(sectionProperties1);

            document1.Append(body1);

            mainDocumentPart1.Document = document1;
        }
        /// <summary>
        /// Determine the type of content control and take neccessary actions
        /// </summary>
        /// <param name="content_control">A SdteElement instance represent a content control</param>
        /// <param name="condional">A DataRow instance contains required values for conditional (used in repeat content control)</param>
        protected void ProcessBasedOnContentControl(SdtElement content_control, DataRow conditional)
        {
            SdtAlias alias = content_control.Descendants <SdtAlias>().FirstOrDefault();

            if (alias.Val.ToString().ToLower() == StaticValues.repeat_cc_name)
            {
                Helper_WordRepeat repeat_helper = new Helper_WordRepeat(content_control);
                repeat_helper.Execute();
            }
            else if (alias.Val.ToString().ToLower() == StaticValues.columntable_cc_name)
            {
                Helper_WordTable_Columns table_helper = new Helper_WordTable_Columns(content_control);
                table_helper.AddConditionToSQLQuery(conditional);
                table_helper.AddDataToTable();
            }
            else if (alias.Val.ToString().ToLower() == StaticValues.rowtable_cc_name)
            {
                Helper_WordTable_Rows table_helper = new Helper_WordTable_Rows(content_control);
                table_helper.AddConditionToSQLQuery(conditional);
                table_helper.AddDataToTable();
            }
            else if (alias.Val.ToString().ToLower() == StaticValues.hybridtable_cc_name)
            {
                Helper_WordTable_Hybrid table_helper = new Helper_WordTable_Hybrid(content_control);
                table_helper.AddConditionToSQLQuery(conditional);
                table_helper.AddDataToTable();
            }
            else if (alias.Val.ToString().ToLower() == StaticValues.barchart_cc_name)
            {
                Helper_WordBarChart chart_helper = new Helper_WordBarChart(content_control);
                chart_helper.AddConditionToSQLQuery(conditional);
                chart_helper.UpdateChartFromSQL();
            }
            else if (alias.Val.ToString().ToLower() == StaticValues.piechart_cc_name)
            {
                Helper_WordPieChart chart_helper = new Helper_WordPieChart(content_control);
                chart_helper.AddConditionToSQLQuery(conditional);
                chart_helper.UpdateChartFromSQL();
            }
            else if (alias.Val.ToString().ToLower() == StaticValues.linechart_cc_name)
            {
                Helper_WordLineChart chart_helper = new Helper_WordLineChart(content_control);
                chart_helper.AddConditionToSQLQuery(conditional);
                chart_helper.UpdateChartFromSQL();
            }
            else if (alias.Val.ToString().ToLower() == StaticValues.val_cc_name)
            {
                Helper_WordBase helper = new Helper_WordBase();
                helper.Init(content_control);
                helper.AddConditionToSQLQuery(conditional);
                string content = helper.GetDataFromDatabaseUsingSQL().Rows[0][0].ToString();

                if (Helper_WordPicture.IsUrl(content) && Helper_WordPicture.IsImageUrl(content))
                {
                    // It is picture
                    SdtElement         image_cc   = content_control.Descendants <SdtElement>().Where(s => s.Descendants <SdtAlias>().FirstOrDefault().Val.ToString().ToLower() == StaticValues.image_cc_name).FirstOrDefault();
                    Helper_WordPicture pic_helper = new Helper_WordPicture(image_cc, content);
                    pic_helper.AddPictureFromUri();
                }
                else // Just normal text
                {
                    Helper_WordBase.ReplaceContentsInContentControl(content_control, content);
                }
            }
        }
예제 #16
0
        private static void ReplaceParagraphParts(OpenXmlElement element, WordprocessingDocument wordDocument)
        {
            //int i = 1;

            // Getting all Paragraph in Xml File

            Drawing  draw     = element.Descendants <Drawing>().FirstOrDefault();
            FileInfo fileInfo = new FileInfo("C:\\Users\\Gaurav Koli\\Downloads\\battlefield_bad_company_2_table_room_parquet-740403.jpg");
            string   embed    = null;

            DocumentFormat.OpenXml.Drawing.Blip blip = null;

            foreach (var paragraph in element.Descendants <Paragraph>())
            {
                //Getting blip Id to get Image Part
                SdtAlias sa = paragraph.Descendants <SdtAlias>().SingleOrDefault();
                if (sa != null && sa.Val == "crmndc_signatureurl")
                {
                    sa.Val = "Change Picture";
                    Console.WriteLine("Done");
                    Drawing dr = paragraph.Descendants <Drawing>().FirstOrDefault();
                    //9525 is EMU per pixel
                    Int64 finalCx = (600 * 9525);
                    Int64 finalCy = (300 * 9525);

                    //resize the image
                    dr.Inline.Extent.Cx = finalCx;
                    dr.Inline.Extent.Cy = finalCy;

                    dr.Inline.Graphic.GraphicData.GetFirstChild <DocumentFormat.OpenXml.Drawing.Pictures.Picture>().ShapeProperties.Transform2D.Extents.Cx = finalCx;
                    dr.Inline.Graphic.GraphicData.GetFirstChild <DocumentFormat.OpenXml.Drawing.Pictures.Picture>().ShapeProperties.Transform2D.Extents.Cy = finalCy;

                    if (dr != null)
                    {
                        blip = dr.Descendants <DocumentFormat.OpenXml.Drawing.Blip>().FirstOrDefault();
                        if (blip != null)
                        {
                            embed = blip.Embed;
                        }
                    }
                }

                //Getting Image part and change the Image

                if (embed != null)
                {
                    IdPartPair idpp = wordDocument.MainDocumentPart.Parts.Where(pa => pa.RelationshipId == embed).FirstOrDefault();
                    if (idpp != null)
                    {
                        ImagePart ip = (ImagePart)idpp.OpenXmlPart;
                        try
                        {
                            using (FileStream fileStream = fileInfo.OpenRead())
                            {
                                ip.FeedData(fileStream);
                                // fileStream.Close();
                            }
                            if (blip != null)
                            {
                                blip.Embed.Value = wordDocument.MainDocumentPart.GetIdOfPart(ip);
                            }
                            Console.WriteLine("done " + wordDocument.MainDocumentPart.GetIdOfPart(ip));
                            // Console.ReadKey();
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.StackTrace);
                            Console.ReadKey();
                        }
                    }
                    embed = null;
                }

                //Changing the Templete Text
                var sdtContentText = paragraph.Descendants <Text>();

                if (sdtContentText != null)
                {
                    foreach (Text text in sdtContentText)
                    {
                        switch (text.Text)
                        {
                        case "<<crmndc_seller1_fullname>>":
                            text.Text = "Common" + i;
                            i++;
                            break;

                        case "Lysaker, ":
                            text.Text = "Common" + i;
                            i++;
                            break;

                        case "21.03.2016":
                            text.Text = "Common" + i;
                            i++;
                            break;

                        case "<<title>>":
                            text.Text = "Common" + i;
                            i++;
                            break;

                        case "<<crmndc_buyer1_fullname>>":
                            text.Text = "Common" + i;
                            i++;
                            break;

                        case "crmndc_insurancecompany_name":
                            text.Text = "Common" + i;
                            i++;
                            break;

                        case "<<":
                            text.Text = "";
                            break;

                        case ">>":
                            text.Text = "";
                            break;

                        default:
                            break;
                        }
                    }
                }
            }
        }