Ejemplo n.º 1
0
        private static int ReplaceHelper(Stream template, bool hasNestedControls)
        {
            int replacedElements = 0;
            using (WordprocessingDocument doc = WordprocessingDocument.Open(template, true))
            {
                MainDocumentPart main = doc.MainDocumentPart;
                var customXmlElements = main.Document.Descendants<CustomXmlElement>().Where(cb => !cb.Descendants<CustomXmlElement>().Any()).ToList();

                foreach (var customXmlElement in customXmlElements)
                {
                    string elementXmlPath = String.Concat(customXmlElement.Ancestors<CustomXmlElement>().Select(ce => ce.GetAttribute("element", customXmlElement.NamespaceUri).Value + "/").ToArray().Reverse()),
                           title = customXmlElement.GetAttribute("element", customXmlElement.NamespaceUri).Value,
                           tagName;
                    OpenXmlElement newElement = null;
                    Random random = new Random();
                    if(!hasNestedControls){
                        tagName = elementXmlPath + customXmlElement.GetAttribute("element", customXmlElement.NamespaceUri).Value;
                    }
                    else{
                        tagName = title;
                    }
                    int newId = random.Next(Int32.MinValue, Int32.MaxValue);

                    SdtProperties sdtPr = new SdtProperties(
                        new SdtAlias() { Val = title },
                        new Tag() { Val = tagName },
                        new SdtId() { Val = newId });

                    if (customXmlElement.GetType() == typeof(CustomXmlBlock))
                    {
                        SdtContentBlock sdtContent = new SdtContentBlock();
                        TransferChildElements(customXmlElement, sdtContent);
                        newElement = new SdtBlock(sdtPr, sdtContent);
                    }
                    else if (customXmlElement.GetType() == typeof(CustomXmlRun))
                    {
                        SdtContentRun sdtContent = new SdtContentRun();
                        TransferChildElements(customXmlElement, sdtContent);
                        newElement = new SdtRun(sdtPr, sdtContent);
                    }
                    else if (customXmlElement.GetType() == typeof(CustomXmlRow))
                    {
                        SdtContentRow sdtContent = new SdtContentRow();
                        TransferChildElements(customXmlElement, sdtContent);
                        newElement = new SdtRow(sdtPr, sdtContent);
                    }
                    else if (customXmlElement.GetType() == typeof(CustomXmlCell))
                    {
                        SdtContentCell sdtContent = new SdtContentCell();
                        TransferChildElements(customXmlElement, sdtContent);
                        newElement = new SdtCell(sdtPr, sdtContent);
                    }
                    customXmlElement.Parent.InsertAfter(newElement, customXmlElement);
                    customXmlElement.Remove();
                }
                replacedElements = customXmlElements.Count;
            }
            return replacedElements;
        }
Ejemplo n.º 2
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;
        }
Ejemplo n.º 3
0
        // ATTENTION : dont work with google doc use CreateParagraph_PageNumber()
        public static SdtBlock CreatePageNumberBlock(string styleId, string text)
        {
            // SdtBlock, <w:sdt>
            SdtBlock sdtBlock = new SdtBlock();

            // Structured Document Tag Properties, <w:sdtPr>
            SdtProperties sdtProperties = new SdtProperties();
            // SdtContentDocPartObject, <w:docPartObj>
            SdtContentDocPartObject docPartObject = new SdtContentDocPartObject();
            // Document Part Gallery Filter, <w:docPartGallery>
            docPartObject.AppendChild(new DocPartGallery { Val = "Page Numbers (Bottom of Page)" });
            docPartObject.AppendChild(new DocPartUnique());
            sdtProperties.AppendChild(docPartObject);
            sdtBlock.SdtProperties = sdtProperties;

            // Block-Level Structured Document Tag Content, <w:sdtContent>
            SdtContentBlock sdtContentBlock = new SdtContentBlock();
            Paragraph paragraph = new Paragraph();
            paragraph.ParagraphProperties = new ParagraphProperties { ParagraphStyleId = new ParagraphStyleId() { Val = styleId } };
            Run run = paragraph.AppendChild(new Run());
            run.AppendChild(new TabStop());
            run.AppendChild(new DW.Text { Text = text });
            run.AppendChild(new TabStop());
            run.AppendChild(new DW.Text { Text = "page ", Space = SpaceProcessingModeValues.Preserve });
            // Complex Field Character, <w:fldChar>
            run.AppendChild(new FieldChar { FieldCharType = FieldCharValues.Begin });
            // Field Code, <w:instrText>
            // "PAGE   \\* MERGEFORMAT"  "PAGE"
            run.AppendChild(new FieldCode("PAGE   \\* MERGEFORMAT"));
            run.AppendChild(new FieldChar { FieldCharType = FieldCharValues.Separate });
            run.AppendChild(new DW.Text { Text = "" });
            run.AppendChild(new FieldChar { FieldCharType = FieldCharValues.End });
            sdtContentBlock.AppendChild(paragraph);
            sdtBlock.SdtContentBlock = sdtContentBlock;

            return sdtBlock;
        }
Ejemplo n.º 4
0
        // Generates content of footerPart1.
        private void GenerateFooterPart1Content(FooterPart footerPart1)
        {
            Footer footer1 = new Footer() { MCAttributes = new MarkupCompatibilityAttributes() { Ignorable = "w14 w15 w16se wp14" } };
            footer1.AddNamespaceDeclaration("wpc", "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas");
            footer1.AddNamespaceDeclaration("cx", "http://schemas.microsoft.com/office/drawing/2014/chartex");
            footer1.AddNamespaceDeclaration("cx1", "http://schemas.microsoft.com/office/drawing/2015/9/8/chartex");
            footer1.AddNamespaceDeclaration("cx2", "http://schemas.microsoft.com/office/drawing/2015/10/21/chartex");
            footer1.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006");
            footer1.AddNamespaceDeclaration("o", "urn:schemas-microsoft-com:office:office");
            footer1.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
            footer1.AddNamespaceDeclaration("m", "http://schemas.openxmlformats.org/officeDocument/2006/math");
            footer1.AddNamespaceDeclaration("v", "urn:schemas-microsoft-com:vml");
            footer1.AddNamespaceDeclaration("wp14", "http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing");
            footer1.AddNamespaceDeclaration("wp", "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing");
            footer1.AddNamespaceDeclaration("w10", "urn:schemas-microsoft-com:office:word");
            footer1.AddNamespaceDeclaration("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main");
            footer1.AddNamespaceDeclaration("w14", "http://schemas.microsoft.com/office/word/2010/wordml");
            footer1.AddNamespaceDeclaration("w15", "http://schemas.microsoft.com/office/word/2012/wordml");
            footer1.AddNamespaceDeclaration("w16se", "http://schemas.microsoft.com/office/word/2015/wordml/symex");
            footer1.AddNamespaceDeclaration("wpg", "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup");
            footer1.AddNamespaceDeclaration("wpi", "http://schemas.microsoft.com/office/word/2010/wordprocessingInk");
            footer1.AddNamespaceDeclaration("wne", "http://schemas.microsoft.com/office/word/2006/wordml");
            footer1.AddNamespaceDeclaration("wps", "http://schemas.microsoft.com/office/word/2010/wordprocessingShape");

            SdtBlock sdtBlock1 = new SdtBlock();

            SdtProperties sdtProperties50 = new SdtProperties();
            SdtId sdtId50 = new SdtId() { Val = -1161223993 };

            SdtContentDocPartObject sdtContentDocPartObject1 = new SdtContentDocPartObject();
            DocPartGallery docPartGallery1 = new DocPartGallery() { Val = "Page Numbers (Bottom of Page)" };
            DocPartUnique docPartUnique1 = new DocPartUnique();

            sdtContentDocPartObject1.Append(docPartGallery1);
            sdtContentDocPartObject1.Append(docPartUnique1);

            sdtProperties50.Append(sdtId50);
            sdtProperties50.Append(sdtContentDocPartObject1);
            SdtEndCharProperties sdtEndCharProperties50 = new SdtEndCharProperties();

            SdtContentBlock sdtContentBlock1 = new SdtContentBlock();

            Paragraph paragraph369 = new Paragraph() { RsidParagraphAddition = "0094109A", RsidParagraphProperties = "00697199", RsidRunAdditionDefault = "00A563A2", ParagraphId = "3CF2B95B", TextId = "59B2ED64" };

            ParagraphProperties paragraphProperties366 = new ParagraphProperties();
            ParagraphStyleId paragraphStyleId26 = new ParagraphStyleId() { Val = "Footer" };

            paragraphProperties366.Append(paragraphStyleId26);

            Hyperlink hyperlink1 = new Hyperlink() { History = true, Id = "rId1" };

            Run run738 = new Run() { RsidRunProperties = "00697199", RsidRunAddition = "00697199" };

            RunProperties runProperties780 = new RunProperties();
            FontSize fontSize1048 = new FontSize() { Val = "20" };
            FontSizeComplexScript fontSizeComplexScript1034 = new FontSizeComplexScript() { Val = "20" };

            runProperties780.Append(fontSize1048);
            runProperties780.Append(fontSizeComplexScript1034);
            Text text700 = new Text();
            text700.Text = "BJC IS Tech Management Standards";

            run738.Append(runProperties780);
            run738.Append(text700);

            hyperlink1.Append(run738);

            Run run739 = new Run() { RsidRunProperties = "00697199", RsidRunAddition = "00697199" };

            RunProperties runProperties781 = new RunProperties();
            FontSize fontSize1049 = new FontSize() { Val = "20" };
            FontSizeComplexScript fontSizeComplexScript1035 = new FontSizeComplexScript() { Val = "20" };

            runProperties781.Append(fontSize1049);
            runProperties781.Append(fontSizeComplexScript1035);
            Text text701 = new Text() { Space = SpaceProcessingModeValues.Preserve };
            text701.Text = "  can be found at: ";

            run739.Append(runProperties781);
            run739.Append(text701);

            Hyperlink hyperlink2 = new Hyperlink() { History = true, Id = "rId2" };

            Run run740 = new Run() { RsidRunProperties = "00697199", RsidRunAddition = "00697199" };

            RunProperties runProperties782 = new RunProperties();
            RunStyle runStyle2 = new RunStyle() { Val = "Hyperlink" };
            FontSize fontSize1050 = new FontSize() { Val = "20" };
            FontSizeComplexScript fontSizeComplexScript1036 = new FontSizeComplexScript() { Val = "20" };

            runProperties782.Append(runStyle2);
            runProperties782.Append(fontSize1050);
            runProperties782.Append(fontSizeComplexScript1036);
            Text text702 = new Text();
            text702.Text = "http://bjcis/sites/techservices/Informational%20Documents/Forms/AllItems.aspx";

            run740.Append(runProperties782);
            run740.Append(text702);

            hyperlink2.Append(run740);

            Run run741 = new Run() { RsidRunProperties = "00697199", RsidRunAddition = "00697199" };

            RunProperties runProperties783 = new RunProperties();
            FontSize fontSize1051 = new FontSize() { Val = "20" };
            FontSizeComplexScript fontSizeComplexScript1037 = new FontSizeComplexScript() { Val = "20" };

            runProperties783.Append(fontSize1051);
            runProperties783.Append(fontSizeComplexScript1037);
            TabChar tabChar45 = new TabChar();

            run741.Append(runProperties783);
            run741.Append(tabChar45);

            Run run742 = new Run() { RsidRunAddition = "00697199" };

            RunProperties runProperties784 = new RunProperties();
            FontSize fontSize1052 = new FontSize() { Val = "20" };
            FontSizeComplexScript fontSizeComplexScript1038 = new FontSizeComplexScript() { Val = "20" };

            runProperties784.Append(fontSize1052);
            runProperties784.Append(fontSizeComplexScript1038);
            Text text703 = new Text() { Space = SpaceProcessingModeValues.Preserve };
            text703.Text = "       ";

            run742.Append(runProperties784);
            run742.Append(text703);

            SdtRun sdtRun50 = new SdtRun();

            SdtProperties sdtProperties51 = new SdtProperties();

            RunProperties runProperties785 = new RunProperties();
            FontSize fontSize1053 = new FontSize() { Val = "20" };
            FontSizeComplexScript fontSizeComplexScript1039 = new FontSizeComplexScript() { Val = "20" };

            runProperties785.Append(fontSize1053);
            runProperties785.Append(fontSizeComplexScript1039);
            SdtId sdtId51 = new SdtId() { Val = 860082579 };

            SdtContentDocPartObject sdtContentDocPartObject2 = new SdtContentDocPartObject();
            DocPartGallery docPartGallery2 = new DocPartGallery() { Val = "Page Numbers (Top of Page)" };
            DocPartUnique docPartUnique2 = new DocPartUnique();

            sdtContentDocPartObject2.Append(docPartGallery2);
            sdtContentDocPartObject2.Append(docPartUnique2);

            sdtProperties51.Append(runProperties785);
            sdtProperties51.Append(sdtId51);
            sdtProperties51.Append(sdtContentDocPartObject2);

            SdtEndCharProperties sdtEndCharProperties51 = new SdtEndCharProperties();

            RunProperties runProperties786 = new RunProperties();
            FontSize fontSize1054 = new FontSize() { Val = "24" };
            FontSizeComplexScript fontSizeComplexScript1040 = new FontSizeComplexScript() { Val = "24" };

            runProperties786.Append(fontSize1054);
            runProperties786.Append(fontSizeComplexScript1040);

            sdtEndCharProperties51.Append(runProperties786);

            SdtContentRun sdtContentRun50 = new SdtContentRun();

            Run run743 = new Run() { RsidRunAddition = "0094109A" };
            Text text704 = new Text() { Space = SpaceProcessingModeValues.Preserve };
            text704.Text = "Page ";

            run743.Append(text704);

            Run run744 = new Run() { RsidRunAddition = "0094109A" };

            RunProperties runProperties787 = new RunProperties();
            Bold bold109 = new Bold();
            BoldComplexScript boldComplexScript4 = new BoldComplexScript();

            runProperties787.Append(bold109);
            runProperties787.Append(boldComplexScript4);
            FieldChar fieldChar1 = new FieldChar() { FieldCharType = FieldCharValues.Begin };

            run744.Append(runProperties787);
            run744.Append(fieldChar1);

            Run run745 = new Run() { RsidRunAddition = "0094109A" };

            RunProperties runProperties788 = new RunProperties();
            Bold bold110 = new Bold();
            BoldComplexScript boldComplexScript5 = new BoldComplexScript();

            runProperties788.Append(bold110);
            runProperties788.Append(boldComplexScript5);
            FieldCode fieldCode1 = new FieldCode() { Space = SpaceProcessingModeValues.Preserve };
            fieldCode1.Text = " PAGE ";

            run745.Append(runProperties788);
            run745.Append(fieldCode1);

            Run run746 = new Run() { RsidRunAddition = "0094109A" };

            RunProperties runProperties789 = new RunProperties();
            Bold bold111 = new Bold();
            BoldComplexScript boldComplexScript6 = new BoldComplexScript();

            runProperties789.Append(bold111);
            runProperties789.Append(boldComplexScript6);
            FieldChar fieldChar2 = new FieldChar() { FieldCharType = FieldCharValues.Separate };

            run746.Append(runProperties789);
            run746.Append(fieldChar2);

            Run run747 = new Run() { RsidRunAddition = "007F6223" };

            RunProperties runProperties790 = new RunProperties();
            Bold bold112 = new Bold();
            BoldComplexScript boldComplexScript7 = new BoldComplexScript();
            NoProof noProof2 = new NoProof();

            runProperties790.Append(bold112);
            runProperties790.Append(boldComplexScript7);
            runProperties790.Append(noProof2);
            Text text705 = new Text();
            text705.Text = "1";

            run747.Append(runProperties790);
            run747.Append(text705);

            Run run748 = new Run() { RsidRunAddition = "0094109A" };

            RunProperties runProperties791 = new RunProperties();
            Bold bold113 = new Bold();
            BoldComplexScript boldComplexScript8 = new BoldComplexScript();

            runProperties791.Append(bold113);
            runProperties791.Append(boldComplexScript8);
            FieldChar fieldChar3 = new FieldChar() { FieldCharType = FieldCharValues.End };

            run748.Append(runProperties791);
            run748.Append(fieldChar3);

            Run run749 = new Run() { RsidRunAddition = "0094109A" };
            Text text706 = new Text() { Space = SpaceProcessingModeValues.Preserve };
            text706.Text = " of ";

            run749.Append(text706);

            Run run750 = new Run() { RsidRunAddition = "0094109A" };

            RunProperties runProperties792 = new RunProperties();
            Bold bold114 = new Bold();
            BoldComplexScript boldComplexScript9 = new BoldComplexScript();

            runProperties792.Append(bold114);
            runProperties792.Append(boldComplexScript9);
            FieldChar fieldChar4 = new FieldChar() { FieldCharType = FieldCharValues.Begin };

            run750.Append(runProperties792);
            run750.Append(fieldChar4);

            Run run751 = new Run() { RsidRunAddition = "0094109A" };

            RunProperties runProperties793 = new RunProperties();
            Bold bold115 = new Bold();
            BoldComplexScript boldComplexScript10 = new BoldComplexScript();

            runProperties793.Append(bold115);
            runProperties793.Append(boldComplexScript10);
            FieldCode fieldCode2 = new FieldCode() { Space = SpaceProcessingModeValues.Preserve };
            fieldCode2.Text = " NUMPAGES  ";

            run751.Append(runProperties793);
            run751.Append(fieldCode2);

            Run run752 = new Run() { RsidRunAddition = "0094109A" };

            RunProperties runProperties794 = new RunProperties();
            Bold bold116 = new Bold();
            BoldComplexScript boldComplexScript11 = new BoldComplexScript();

            runProperties794.Append(bold116);
            runProperties794.Append(boldComplexScript11);
            FieldChar fieldChar5 = new FieldChar() { FieldCharType = FieldCharValues.Separate };

            run752.Append(runProperties794);
            run752.Append(fieldChar5);

            Run run753 = new Run() { RsidRunAddition = "007F6223" };

            RunProperties runProperties795 = new RunProperties();
            Bold bold117 = new Bold();
            BoldComplexScript boldComplexScript12 = new BoldComplexScript();
            NoProof noProof3 = new NoProof();

            runProperties795.Append(bold117);
            runProperties795.Append(boldComplexScript12);
            runProperties795.Append(noProof3);
            Text text707 = new Text();
            text707.Text = "8";

            run753.Append(runProperties795);
            run753.Append(text707);

            Run run754 = new Run() { RsidRunAddition = "0094109A" };

            RunProperties runProperties796 = new RunProperties();
            Bold bold118 = new Bold();
            BoldComplexScript boldComplexScript13 = new BoldComplexScript();

            runProperties796.Append(bold118);
            runProperties796.Append(boldComplexScript13);
            FieldChar fieldChar6 = new FieldChar() { FieldCharType = FieldCharValues.End };

            run754.Append(runProperties796);
            run754.Append(fieldChar6);

            sdtContentRun50.Append(run743);
            sdtContentRun50.Append(run744);
            sdtContentRun50.Append(run745);
            sdtContentRun50.Append(run746);
            sdtContentRun50.Append(run747);
            sdtContentRun50.Append(run748);
            sdtContentRun50.Append(run749);
            sdtContentRun50.Append(run750);
            sdtContentRun50.Append(run751);
            sdtContentRun50.Append(run752);
            sdtContentRun50.Append(run753);
            sdtContentRun50.Append(run754);

            sdtRun50.Append(sdtProperties51);
            sdtRun50.Append(sdtEndCharProperties51);
            sdtRun50.Append(sdtContentRun50);

            paragraph369.Append(paragraphProperties366);
            paragraph369.Append(hyperlink1);
            paragraph369.Append(run739);
            paragraph369.Append(hyperlink2);
            paragraph369.Append(run741);
            paragraph369.Append(run742);
            paragraph369.Append(sdtRun50);

            sdtContentBlock1.Append(paragraph369);

            sdtBlock1.Append(sdtProperties50);
            sdtBlock1.Append(sdtEndCharProperties50);
            sdtBlock1.Append(sdtContentBlock1);

            Paragraph paragraph370 = new Paragraph() { RsidParagraphAddition = "0094109A", RsidParagraphProperties = "000F55C6", RsidRunAdditionDefault = "0094109A", ParagraphId = "0AAC1AD4", TextId = "7EFCA27E" };

            ParagraphProperties paragraphProperties367 = new ParagraphProperties();
            ParagraphStyleId paragraphStyleId27 = new ParagraphStyleId() { Val = "Footer" };
            Justification justification77 = new Justification() { Val = JustificationValues.Center };

            paragraphProperties367.Append(paragraphStyleId27);
            paragraphProperties367.Append(justification77);

            paragraph370.Append(paragraphProperties367);

            footer1.Append(sdtBlock1);
            footer1.Append(paragraph370);

            footerPart1.Footer = footer1;
        }
Ejemplo n.º 5
0
        // Generates content of footerPart2.
        private void GenerateFooterPart2Content(FooterPart footerPart2)
        {
            Footer footer2 = new Footer() {MCAttributes = new MarkupCompatibilityAttributes() {Ignorable = "w14 wp14"}};
            footer2.AddNamespaceDeclaration("wpc", "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas");
            footer2.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006");
            footer2.AddNamespaceDeclaration("o", "urn:schemas-microsoft-com:office:office");
            footer2.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
            footer2.AddNamespaceDeclaration("m", "http://schemas.openxmlformats.org/officeDocument/2006/math");
            footer2.AddNamespaceDeclaration("v", "urn:schemas-microsoft-com:vml");
            footer2.AddNamespaceDeclaration("wp14", "http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing");
            footer2.AddNamespaceDeclaration("wp", "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing");
            footer2.AddNamespaceDeclaration("w10", "urn:schemas-microsoft-com:office:word");
            footer2.AddNamespaceDeclaration("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main");
            footer2.AddNamespaceDeclaration("w14", "http://schemas.microsoft.com/office/word/2010/wordml");
            footer2.AddNamespaceDeclaration("wpg", "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup");
            footer2.AddNamespaceDeclaration("wpi", "http://schemas.microsoft.com/office/word/2010/wordprocessingInk");
            footer2.AddNamespaceDeclaration("wne", "http://schemas.microsoft.com/office/word/2006/wordml");
            footer2.AddNamespaceDeclaration("wps", "http://schemas.microsoft.com/office/word/2010/wordprocessingShape");

            SdtBlock sdtBlock1 = new SdtBlock();

            SdtProperties sdtProperties1 = new SdtProperties();
            SdtId sdtId1 = new SdtId() {Val = -1382393284};

            SdtContentDocPartObject sdtContentDocPartObject1 = new SdtContentDocPartObject();
            DocPartGallery docPartGallery1 = new DocPartGallery() {Val = "Page Numbers (Bottom of Page)"};
            DocPartUnique docPartUnique1 = new DocPartUnique();

            sdtContentDocPartObject1.Append(docPartGallery1);
            sdtContentDocPartObject1.Append(docPartUnique1);

            sdtProperties1.Append(sdtId1);
            sdtProperties1.Append(sdtContentDocPartObject1);
            SdtEndCharProperties sdtEndCharProperties1 = new SdtEndCharProperties();

            SdtContentBlock sdtContentBlock1 = new SdtContentBlock();

            SdtBlock sdtBlock2 = new SdtBlock();

            SdtProperties sdtProperties2 = new SdtProperties();
            SdtId sdtId2 = new SdtId() {Val = 98381352};

            SdtContentDocPartObject sdtContentDocPartObject2 = new SdtContentDocPartObject();
            DocPartGallery docPartGallery2 = new DocPartGallery() {Val = "Page Numbers (Top of Page)"};
            DocPartUnique docPartUnique2 = new DocPartUnique();

            sdtContentDocPartObject2.Append(docPartGallery2);
            sdtContentDocPartObject2.Append(docPartUnique2);

            sdtProperties2.Append(sdtId2);
            sdtProperties2.Append(sdtContentDocPartObject2);
            SdtEndCharProperties sdtEndCharProperties2 = new SdtEndCharProperties();

            SdtContentBlock sdtContentBlock2 = new SdtContentBlock();

            Paragraph paragraph28 = new Paragraph() {RsidParagraphAddition = "0005059E", RsidRunAdditionDefault = "0005059E"};

            ParagraphProperties paragraphProperties9 = new ParagraphProperties();
            ParagraphStyleId paragraphStyleId3 = new ParagraphStyleId() {Val = "Footer"};

            paragraphProperties9.Append(paragraphStyleId3);

            Run run44 = new Run();
            Text text29 = new Text() {Space = SpaceProcessingModeValues.Preserve};
            text29.Text = "Page ";

            run44.Append(text29);

            Run run45 = new Run();

            RunProperties runProperties23 = new RunProperties();
            Bold bold16 = new Bold();
            BoldComplexScript boldComplexScript16 = new BoldComplexScript();
            FontSize fontSize15 = new FontSize() {Val = "24"};
            FontSizeComplexScript fontSizeComplexScript15 = new FontSizeComplexScript() {Val = "24"};

            runProperties23.Append(bold16);
            runProperties23.Append(boldComplexScript16);
            runProperties23.Append(fontSize15);
            runProperties23.Append(fontSizeComplexScript15);
            FieldChar fieldChar7 = new FieldChar() {FieldCharType = FieldCharValues.Begin};

            run45.Append(runProperties23);
            run45.Append(fieldChar7);

            Run run46 = new Run();

            RunProperties runProperties24 = new RunProperties();
            Bold bold17 = new Bold();
            BoldComplexScript boldComplexScript17 = new BoldComplexScript();

            runProperties24.Append(bold17);
            runProperties24.Append(boldComplexScript17);
            FieldCode fieldCode3 = new FieldCode() {Space = SpaceProcessingModeValues.Preserve};
            fieldCode3.Text = " PAGE ";

            run46.Append(runProperties24);
            run46.Append(fieldCode3);

            Run run47 = new Run();

            RunProperties runProperties25 = new RunProperties();
            Bold bold18 = new Bold();
            BoldComplexScript boldComplexScript18 = new BoldComplexScript();
            FontSize fontSize16 = new FontSize() {Val = "24"};
            FontSizeComplexScript fontSizeComplexScript16 = new FontSizeComplexScript() {Val = "24"};

            runProperties25.Append(bold18);
            runProperties25.Append(boldComplexScript18);
            runProperties25.Append(fontSize16);
            runProperties25.Append(fontSizeComplexScript16);
            FieldChar fieldChar8 = new FieldChar() {FieldCharType = FieldCharValues.Separate};

            run47.Append(runProperties25);
            run47.Append(fieldChar8);

            Run run48 = new Run() {RsidRunAddition = "00FB1F22"};

            RunProperties runProperties26 = new RunProperties();
            Bold bold19 = new Bold();
            BoldComplexScript boldComplexScript19 = new BoldComplexScript();
            NoProof noProof23 = new NoProof();

            runProperties26.Append(bold19);
            runProperties26.Append(boldComplexScript19);
            runProperties26.Append(noProof23);
            Text text30 = new Text();
            text30.Text = "2";

            run48.Append(runProperties26);
            run48.Append(text30);

            Run run49 = new Run();

            RunProperties runProperties27 = new RunProperties();
            Bold bold20 = new Bold();
            BoldComplexScript boldComplexScript20 = new BoldComplexScript();
            FontSize fontSize17 = new FontSize() {Val = "24"};
            FontSizeComplexScript fontSizeComplexScript17 = new FontSizeComplexScript() {Val = "24"};

            runProperties27.Append(bold20);
            runProperties27.Append(boldComplexScript20);
            runProperties27.Append(fontSize17);
            runProperties27.Append(fontSizeComplexScript17);
            FieldChar fieldChar9 = new FieldChar() {FieldCharType = FieldCharValues.End};

            run49.Append(runProperties27);
            run49.Append(fieldChar9);

            Run run50 = new Run();
            Text text31 = new Text() {Space = SpaceProcessingModeValues.Preserve};
            text31.Text = " of ";

            run50.Append(text31);

            Run run51 = new Run();

            RunProperties runProperties28 = new RunProperties();
            Bold bold21 = new Bold();
            BoldComplexScript boldComplexScript21 = new BoldComplexScript();
            FontSize fontSize18 = new FontSize() {Val = "24"};
            FontSizeComplexScript fontSizeComplexScript18 = new FontSizeComplexScript() {Val = "24"};

            runProperties28.Append(bold21);
            runProperties28.Append(boldComplexScript21);
            runProperties28.Append(fontSize18);
            runProperties28.Append(fontSizeComplexScript18);
            FieldChar fieldChar10 = new FieldChar() {FieldCharType = FieldCharValues.Begin};

            run51.Append(runProperties28);
            run51.Append(fieldChar10);

            Run run52 = new Run();

            RunProperties runProperties29 = new RunProperties();
            Bold bold22 = new Bold();
            BoldComplexScript boldComplexScript22 = new BoldComplexScript();

            runProperties29.Append(bold22);
            runProperties29.Append(boldComplexScript22);
            FieldCode fieldCode4 = new FieldCode() {Space = SpaceProcessingModeValues.Preserve};
            fieldCode4.Text = " NUMPAGES  ";

            run52.Append(runProperties29);
            run52.Append(fieldCode4);

            Run run53 = new Run();

            RunProperties runProperties30 = new RunProperties();
            Bold bold23 = new Bold();
            BoldComplexScript boldComplexScript23 = new BoldComplexScript();
            FontSize fontSize19 = new FontSize() {Val = "24"};
            FontSizeComplexScript fontSizeComplexScript19 = new FontSizeComplexScript() {Val = "24"};

            runProperties30.Append(bold23);
            runProperties30.Append(boldComplexScript23);
            runProperties30.Append(fontSize19);
            runProperties30.Append(fontSizeComplexScript19);
            FieldChar fieldChar11 = new FieldChar() {FieldCharType = FieldCharValues.Separate};

            run53.Append(runProperties30);
            run53.Append(fieldChar11);

            Run run54 = new Run() {RsidRunAddition = "00FB1F22"};

            RunProperties runProperties31 = new RunProperties();
            Bold bold24 = new Bold();
            BoldComplexScript boldComplexScript24 = new BoldComplexScript();
            NoProof noProof24 = new NoProof();

            runProperties31.Append(bold24);
            runProperties31.Append(boldComplexScript24);
            runProperties31.Append(noProof24);
            Text text32 = new Text();
            text32.Text = "37";

            run54.Append(runProperties31);
            run54.Append(text32);

            Run run55 = new Run();

            RunProperties runProperties32 = new RunProperties();
            Bold bold25 = new Bold();
            BoldComplexScript boldComplexScript25 = new BoldComplexScript();
            FontSize fontSize20 = new FontSize() {Val = "24"};
            FontSizeComplexScript fontSizeComplexScript20 = new FontSizeComplexScript() {Val = "24"};

            runProperties32.Append(bold25);
            runProperties32.Append(boldComplexScript25);
            runProperties32.Append(fontSize20);
            runProperties32.Append(fontSizeComplexScript20);
            FieldChar fieldChar12 = new FieldChar() {FieldCharType = FieldCharValues.End};

            run55.Append(runProperties32);
            run55.Append(fieldChar12);

            paragraph28.Append(paragraphProperties9);
            paragraph28.Append(run44);
            paragraph28.Append(run45);
            paragraph28.Append(run46);
            paragraph28.Append(run47);
            paragraph28.Append(run48);
            paragraph28.Append(run49);
            paragraph28.Append(run50);
            paragraph28.Append(run51);
            paragraph28.Append(run52);
            paragraph28.Append(run53);
            paragraph28.Append(run54);
            paragraph28.Append(run55);

            sdtContentBlock2.Append(paragraph28);

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

            sdtContentBlock1.Append(sdtBlock2);

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

            Paragraph paragraph29 = new Paragraph() {RsidParagraphAddition = "0005059E", RsidRunAdditionDefault = "0005059E"};

            ParagraphProperties paragraphProperties10 = new ParagraphProperties();
            ParagraphStyleId paragraphStyleId4 = new ParagraphStyleId() {Val = "Footer"};

            paragraphProperties10.Append(paragraphStyleId4);

            paragraph29.Append(paragraphProperties10);

            footer2.Append(sdtBlock1);
            footer2.Append(paragraph29);

            footerPart2.Footer = footer2;
        }
        // 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;
        }
Ejemplo n.º 7
0
        static void AddWatermark(WordprocessingDocument doc, string textWatermark)
        {
            if (doc.MainDocumentPart.HeaderParts.Count() == 0)
            {
                doc.MainDocumentPart.DeleteParts(doc.MainDocumentPart.HeaderParts);
                var newHeaderPart = doc.MainDocumentPart.AddNewPart <HeaderPart>();
                var rId           = doc.MainDocumentPart.GetIdOfPart(newHeaderPart);
                var headerRef     = new HeaderReference();
                headerRef.Id = rId;
                var sectionProps = doc.MainDocumentPart.Document.Body.Elements <SectionProperties>().LastOrDefault();
                if (sectionProps == null)
                {
                    sectionProps = new SectionProperties();
                    doc.MainDocumentPart.Document.Body.Append(sectionProps);
                }
                sectionProps.RemoveAllChildren <HeaderReference>();
                sectionProps.Append(headerRef);

                newHeaderPart.Header = MakeHeader();
                newHeaderPart.Header.Save();
            }

            foreach (HeaderPart headerPart in doc.MainDocumentPart.HeaderParts)
            {
                var sdtBlock1      = new SdtBlock();
                var sdtProperties1 = new SdtProperties();
                var sdtId1         = new SdtId()
                {
                    Val = 87908844
                };
                var sdtContentDocPartObject1 = new SdtContentDocPartObject();
                var docPartGallery1          = new DocPartGallery()
                {
                    Val = "Watermarks"
                };
                var docPartUnique1 = new DocPartUnique();
                sdtContentDocPartObject1.Append(docPartGallery1);
                sdtContentDocPartObject1.Append(docPartUnique1);
                sdtProperties1.Append(sdtId1);
                sdtProperties1.Append(sdtContentDocPartObject1);

                var sdtContentBlock1 = new SdtContentBlock();
                var paragraph2       = new Paragraph()
                {
                    RsidParagraphAddition  = "00656E18",
                    RsidRunAdditionDefault = "00656E18"
                };
                var paragraphProperties2 = new ParagraphProperties();
                var paragraphStyleId2    = new ParagraphStyleId()
                {
                    Val = "Header"
                };
                paragraphProperties2.Append(paragraphStyleId2);
                var run1           = new Run();
                var runProperties1 = new RunProperties();
                var noProof1       = new NoProof();
                var languages1     = new Languages()
                {
                    EastAsia = "zh-TW"
                };
                runProperties1.Append(noProof1);
                runProperties1.Append(languages1);
                var picture1   = new Picture();
                var shapetype1 = new Shapetype()
                {
                    Id             = "_x0000_t136",
                    CoordinateSize = "21600,21600",
                    OptionalNumber = 136,
                    Adjustment     = "10800",
                    EdgePath       = "m@7,l@8,m@5,21600l@6,21600e"
                };
                var formulas1 = new Formulas();
                var formula1  = new Formula()
                {
                    Equation = "sum #0 0 10800"
                };
                var formula2 = new Formula()
                {
                    Equation = "prod #0 2 1"
                };
                var formula3 = new Formula()
                {
                    Equation = "sum 21600 0 @1"
                };
                var formula4 = new Formula()
                {
                    Equation = "sum 0 0 @2"
                };
                var formula5 = new Formula()
                {
                    Equation = "sum 21600 0 @3"
                };
                var formula6 = new Formula()
                {
                    Equation = "if @0 @3 0"
                };
                var formula7 = new Formula()
                {
                    Equation = "if @0 21600 @1"
                };
                var formula8 = new Formula()
                {
                    Equation = "if @0 0 @2"
                };
                var formula9 = new Formula()
                {
                    Equation = "if @0 @4 21600"
                };
                var formula10 = new Formula()
                {
                    Equation = "mid @5 @6"
                };
                var formula11 = new Formula()
                {
                    Equation = "mid @8 @5"
                };
                var formula12 = new Formula()
                {
                    Equation = "mid @7 @8"
                };
                var formula13 = new Formula()
                {
                    Equation = "mid @6 @7"
                };
                var formula14 = new Formula()
                {
                    Equation = "sum @6 0 @5"
                };

                formulas1.Append(formula1);
                formulas1.Append(formula2);
                formulas1.Append(formula3);
                formulas1.Append(formula4);
                formulas1.Append(formula5);
                formulas1.Append(formula6);
                formulas1.Append(formula7);
                formulas1.Append(formula8);
                formulas1.Append(formula9);
                formulas1.Append(formula10);
                formulas1.Append(formula11);
                formulas1.Append(formula12);
                formulas1.Append(formula13);
                formulas1.Append(formula14);
                var path1 = new Path()
                {
                    AllowTextPath       = TrueFalseValue.FromBoolean(true),
                    ConnectionPointType = ConnectValues.Custom,
                    ConnectionPoints    = "@9,0;@10,10800;@11,21600;@12,10800",
                    ConnectAngles       = "270,180,90,0"
                };
                var textPath1 = new TextPath()
                {
                    On       = TrueFalseValue.FromBoolean(true),
                    FitShape = TrueFalseValue.FromBoolean(true)
                };
                var shapeHandles1 = new ShapeHandles();

                var shapeHandle1 = new ShapeHandle()
                {
                    Position = "#0,bottomRight",
                    XRange   = "6629,14971"
                };

                shapeHandles1.Append(shapeHandle1);

                var lock1 = new Lock
                {
                    Extension = ExtensionHandlingBehaviorValues.Edit,
                    TextLock  = TrueFalseValue.FromBoolean(true),
                    ShapeType = TrueFalseValue.FromBoolean(true)
                };

                shapetype1.Append(formulas1);
                shapetype1.Append(path1);
                shapetype1.Append(textPath1);
                shapetype1.Append(shapeHandles1);
                shapetype1.Append(lock1);
                var shape1 = new Shape()
                {
                    Id             = "PowerPlusWaterMarkObject357922611",
                    Style          = "position:absolute;left:0;text-align:left;margin-left:0;margin-top:0;width:527.85pt;height:131.95pt;rotation:315;z-index:-251656192;mso-position-horizontal:center;mso-position-horizontal-relative:margin;mso-position-vertical:center;mso-position-vertical-relative:margin",
                    OptionalString = "_x0000_s2049",
                    AllowInCell    = TrueFalseValue.FromBoolean(true),
                    FillColor      = "silver",
                    Stroked        = TrueFalseValue.FromBoolean(false),
                    Type           = "#_x0000_t136"
                };


                var fill1 = new Fill()
                {
                    Opacity = ".5"
                };
                TextPath textPath2 = new TextPath()
                {
                    Style  = "font-family:\"Calibri\";font-size:1pt",
                    String = textWatermark
                };

                var textWrap1 = new TextWrap()
                {
                    AnchorX = HorizontalAnchorValues.Margin,
                    AnchorY = VerticalAnchorValues.Margin
                };

                shape1.Append(fill1);
                shape1.Append(textPath2);
                shape1.Append(textWrap1);
                picture1.Append(shapetype1);
                picture1.Append(shape1);
                run1.Append(runProperties1);
                run1.Append(picture1);
                paragraph2.Append(paragraphProperties2);
                paragraph2.Append(run1);
                sdtContentBlock1.Append(paragraph2);
                sdtBlock1.Append(sdtProperties1);
                sdtBlock1.Append(sdtContentBlock1);
                headerPart.Header.Append(sdtBlock1);
                headerPart.Header.Save();
                //break;
            }
        }
Ejemplo n.º 8
0
        public void CreateMSWordDocument(Guid identifier)
        {
            var    myResume    = _resumeManagerRepository.Get(m => m.Guid.Equals(identifier)).First().Resume;
            string projPath    = HttpContext.Current.Server.MapPath("~/Content/");
            string outFilePath = Path.Combine(projPath, "doc", myResume.ResumeManager.Link);

            byte[] templateBytes = System.IO.File.ReadAllBytes(projPath + "MSWordTemplates\\template4.dotx");

            using (MemoryStream templateStream = new MemoryStream())
            {
                templateStream.Write(templateBytes, 0, (int)templateBytes.Length);

                using (WordprocessingDocument doc = WordprocessingDocument.Open(templateStream, true))
                {
                    doc.ChangeDocumentType(WordprocessingDocumentType.Document);
                    var mainPart = doc.MainDocumentPart;

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

                    // Create a new attachedTemplate and specify a relationship ID
                    AttachedTemplate attachedTemplate1 = new AttachedTemplate()
                    {
                        Id = "relationId1"
                    };

                    // Append the attached template to the DocumentSettingsPart
                    documentSettingPart1.Settings.Append(attachedTemplate1);

                    // Add an ExternalRelationShip of type AttachedTemplate.
                    // Specify the path of template and the relationship ID
                    documentSettingPart1.AddExternalRelationship("http://schemas.openxmlformats.org/officeDocument/2006/relationships/attachedTemplate", new Uri(projPath + "MSWordTemplates\\template4.dotx", UriKind.Absolute), "relationId1");

                    string fullname = string.Format("{0} {1}", myResume.FirstName, myResume.LastName);
                    SetCCText(mainPart, "FullName", fullname);

                    SetCCText(mainPart, "Goal", myResume.Goal);
                    SetCCText(mainPart, "Location", myResume.CurrentLocation);

                    string email = myResume.Contacts.First(c => c.ContactTitle.Title.Equals("EMail")).Data;
                    SetCCText(mainPart, "Email", email);

                    string phone = myResume.Contacts.First(c => c.ContactTitle.Title.Equals("Phone")).Data;
                    SetCCText(mainPart, "Phone", phone);

                    RemoveCCChild(mainPart, "OtherContacts");
                    foreach (var contact in myResume.Contacts.Where(c => !c.ContactTitle.Title.Equals("EMail") && !c.ContactTitle.Title.Equals("Phone")))
                    {
                        AppendCCText(mainPart, "OtherContacts", string.Format("{0}: {1}", contact.ContactTitle.Title, contact.Data));
                    }

                    // ОБРАЗОВАНИЕ
                    if (myResume.Education.Count > 0)
                    {
                        SdtBlock contentControl = mainPart.Document.Body.Descendants <SdtBlock>().Where(r => r.SdtProperties.GetFirstChild <Tag>().Val == "Section_Education").Single();
                        Table    theTable       = contentControl.Descendants <Table>().Single();
                        TableRow defaultRow     = theTable.Elements <TableRow>().Last();

                        foreach (var institution in myResume.Education)
                        {
                            TableRow rowCopy = (TableRow)defaultRow.CloneNode(true);

                            // период учебы
                            var periodRun = rowCopy.Descendants <TableCell>().ElementAt(0).GetFirstChild <Paragraph>().GetFirstChild <Run>();
                            periodRun.GetFirstChild <Text>().Text = string.Format("{0} –", institution.From.Format());
                            periodRun.Append(new Break());
                            periodRun.Append(new Text(institution.To.Format()));

                            // описание уч. заведениия:
                            // название и город
                            TableCell secondColumn = rowCopy.Descendants <TableCell>().ElementAt(1);
                            SetCCText(secondColumn, "InstitutionName", string.Format("{0}, г. {1}", institution.Name, institution.City));

                            // кафедра
                            if (string.IsNullOrEmpty(institution.Department))
                            {
                                secondColumn.Descendants <SdtRun>().Where(r => r.SdtProperties.GetFirstChild <Tag>().Val == "InstitutionDepartment").Single().Parent.Remove();
                            }
                            else
                            {
                                SetCCText(secondColumn, "InstitutionDepartment", institution.Department);
                            }

                            // специальность
                            SetCCText(secondColumn, "InstitutionSpeciality", institution.Specialty);
                            secondColumn.Elements <Paragraph>().Last().Append(new Run(new Break()));

                            theTable.AppendChild(rowCopy);
                        }
                        theTable.RemoveChild(defaultRow);
                    }
                    else
                    {
                        mainPart.Document.Body.Descendants <SdtBlock>().Where(r => r.SdtProperties.GetFirstChild <Tag>().Val == "Section_Education").Single().Remove();
                    }

                    // ОПЫТ РАБОТЫ
                    if (myResume.WorkExp.Count > 0)
                    {
                        SdtBlock contentControl = mainPart.Document.Body.Descendants <SdtBlock>().Where(r => r.SdtProperties.GetFirstChild <Tag>().Val == "Section_Experience").Single();
                        Table    theTable       = contentControl.Descendants <Table>().Single();
                        TableRow defaultRow     = theTable.Elements <TableRow>().Last();

                        foreach (var workPlace in myResume.WorkExp)
                        {
                            TableRow rowCopy = (TableRow)defaultRow.CloneNode(true);

                            // период в который работали
                            var periodRun = rowCopy.Descendants <TableCell>().ElementAt(0).GetFirstChild <Paragraph>().GetFirstChild <Run>();
                            periodRun.GetFirstChild <Text>().Text = string.Format("{0} –", workPlace.From.Format());
                            periodRun.Append(new Break());
                            periodRun.Append(new Text(workPlace.To.Format()));

                            // описание работы:
                            // название работы и город
                            TableCell secondColumn = rowCopy.Descendants <TableCell>().ElementAt(1);
                            SetCCText(secondColumn, "WorkplaceName", string.Format("{0}, г. {1}", workPlace.Name, workPlace.City));

                            // должность
                            SetCCText(secondColumn, "WorkplacePosition", workPlace.Position);

                            // обязанности
                            if (workPlace.Duties.Count > 0)
                            {
                                RemoveCCChild(secondColumn, "WorkplaceDuties");
                                foreach (var duty in workPlace.Duties)
                                {
                                    AppendCCText(secondColumn, "WorkplaceDuties", string.Format("– {0}", duty.Name));
                                }
                            }
                            else
                            {
                                secondColumn.Descendants <SdtRun>().Where(r => r.SdtProperties.GetFirstChild <Tag>().Val == "WorkplaceDuties").Single().Parent.Remove();
                            }

                            //secondColumn.Elements<Paragraph>().Last().Append(new Run(new Break()));

                            theTable.AppendChild(rowCopy);
                        }
                        theTable.RemoveChild(defaultRow);
                    }
                    else
                    {
                        mainPart.Document.Body.Descendants <SdtBlock>().Where(r => r.SdtProperties.GetFirstChild <Tag>().Val == "Section_Experience").Single().Remove();
                    }


                    // СЕРТИФИКАТЫ
                    if (myResume.CertificatesAndTrainings.Count > 0)
                    {
                        RemoveCCChild(mainPart, "Certificates");
                        foreach (var certificate in myResume.CertificatesAndTrainings)
                        {
                            AppendCCText(mainPart, "Certificates", string.Format("{0} – {1}{2}", certificate.Date.Year, certificate.Name, certificate.Location != null ? string.Format(", г. {0}", certificate.Location) : ""));
                        }
                    }
                    else
                    {
                        RemoveCC(mainPart, "Section_Certificates");
                    }

                    // ЯЗЫКИ
                    if (myResume.Languages.Count > 0)
                    {
                        SdtBlock        contentControl = mainPart.Document.Body.Descendants <SdtBlock>().Where(r => r.SdtProperties.GetFirstChild <Tag>().Val == "Languages").Single();
                        SdtContentBlock contentRun     = contentControl.GetFirstChild <SdtContentBlock>();
                        Paragraph       defaultLi      = contentRun.GetFirstChild <Paragraph>();

                        foreach (var language in myResume.Languages)
                        {
                            Paragraph copy = (Paragraph)defaultLi.CloneNode(true);
                            copy.Descendants <Text>().Where(t => t.Text == "lang").Single().Text  = language.Name;
                            copy.Descendants <Text>().Where(t => t.Text == "level").Single().Text = language.Level;
                            contentRun.Append(copy);
                        }
                        contentRun.RemoveChild(defaultLi);
                    }
                    else
                    {
                        RemoveCC(mainPart, "Section_Languages");
                    }

                    // ЛИЧНЫЕ КАЧЕСТВА
                    if (myResume.PersonalQualities.Count > 0)
                    {
                        SdtBlock        contentControl = mainPart.Document.Body.Descendants <SdtBlock>().Where(r => r.SdtProperties.GetFirstChild <Tag>().Val == "PersonalQualities").Single();
                        SdtContentBlock contentRun     = contentControl.GetFirstChild <SdtContentBlock>();
                        Paragraph       defaultLi      = contentRun.GetFirstChild <Paragraph>();

                        foreach (var quality in myResume.PersonalQualities)
                        {
                            Paragraph copy = (Paragraph)defaultLi.CloneNode(true);
                            copy.Descendants <Text>().Where(t => t.Text == "quality").Single().Text = quality.Name;
                            contentRun.Append(copy);
                        }
                        contentRun.RemoveChild(defaultLi);
                    }
                    else
                    {
                        mainPart.Document.Body.Descendants <SdtBlock>().Where(r => r.SdtProperties.GetFirstChild <Tag>().Val == "Section_PersonalQualities").Single().Remove();
                    }

                    // НАВЫКИ
                    if (myResume.Skills.Count > 0)
                    {
                        SdtBlock        contentControl = mainPart.Document.Body.Descendants <SdtBlock>().Where(r => r.SdtProperties.GetFirstChild <Tag>().Val == "Skills").Single();
                        SdtContentBlock contentRun     = contentControl.GetFirstChild <SdtContentBlock>();
                        Paragraph       defaultLi      = contentRun.GetFirstChild <Paragraph>();

                        foreach (var skill in myResume.Skills)
                        {
                            Paragraph copy = (Paragraph)defaultLi.CloneNode(true);
                            copy.Descendants <Text>().Where(t => t.Text == "skill").Single().Text = skill.Name;
                            contentRun.Append(copy);
                        }
                        contentRun.RemoveChild(defaultLi);
                    }
                    else
                    {
                        mainPart.Document.Body.Descendants <SdtBlock>().Where(r => r.SdtProperties.GetFirstChild <Tag>().Val == "Section_Skills").Single().Remove();
                    }

                    mainPart.Document.Save();
                }
                File.WriteAllBytes(outFilePath, templateStream.ToArray());
            }
        }
Ejemplo n.º 9
0
        // Generates content of mainDocumentPart1.
        private void GenerateMainDocumentPart1Content(MainDocumentPart mainDocumentPart1)
        {
            Document document1 = new Document()
            {
                MCAttributes = new MarkupCompatibilityAttributes()
                {
                    Ignorable = "w14 w15 w16se wp14"
                }
            };

            document1.AddNamespaceDeclaration("wpc", "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas");
            document1.AddNamespaceDeclaration("cx", "http://schemas.microsoft.com/office/drawing/2014/chartex");
            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/2012/wordml");
            document1.AddNamespaceDeclaration("w16se", "http://schemas.microsoft.com/office/word/2015/wordml/symex");
            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();

            Paragraph paragraph1 = new Paragraph()
            {
                RsidParagraphAddition = "00EC73B1", RsidRunAdditionDefault = "00EC73B1"
            };

            Run  run1  = new Run();
            Text text1 = new Text();

            text1.Text = "Test 1";

            run1.Append(text1);

            paragraph1.Append(run1);

            SdtBlock sdtBlock1 = new SdtBlock();

            SdtProperties sdtProperties1 = new SdtProperties();
            Tag           tag1           = new Tag()
            {
                Val = "testa"
            };
            SdtId sdtId1 = new SdtId()
            {
                Val = -1218056249
            };

            SdtPlaceholder   sdtPlaceholder1   = new SdtPlaceholder();
            DocPartReference docPartReference1 = new DocPartReference()
            {
                Val = "DefaultPlaceholder_-1854013440"
            };

            sdtPlaceholder1.Append(docPartReference1);

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

            SdtContentBlock sdtContentBlock1 = new SdtContentBlock();

            Paragraph paragraph2 = new Paragraph()
            {
                RsidParagraphAddition = "001E13C4", RsidRunAdditionDefault = "001E13C4"
            };

            Run  run2  = new Run();
            Text text2 = new Text();

            text2.Text = "Test a";

            run2.Append(text2);

            paragraph2.Append(run2);

            sdtContentBlock1.Append(paragraph2);

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

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

            Run   run3   = new Run();
            Break break1 = new Break()
            {
                Type = BreakValues.Page
            };

            run3.Append(break1);

            paragraph3.Append(run3);

            Paragraph paragraph4 = new Paragraph()
            {
                RsidParagraphAddition = "00A15A83", RsidRunAdditionDefault = "00EC73B1"
            };

            Run run4 = new Run();
            LastRenderedPageBreak lastRenderedPageBreak1 = new LastRenderedPageBreak();
            Text text3 = new Text();

            text3.Text = "Test 2";

            run4.Append(lastRenderedPageBreak1);
            run4.Append(text3);

            paragraph4.Append(run4);
            BookmarkStart bookmarkStart1 = new BookmarkStart()
            {
                Name = "_GoBack", DisplacedByCustomXml = DisplacedByCustomXmlValues.Next, Id = "0"
            };

            SdtBlock sdtBlock2 = new SdtBlock();

            SdtProperties sdtProperties2 = new SdtProperties();
            Tag           tag2           = new Tag()
            {
                Val = "testb"
            };
            SdtId sdtId2 = new SdtId()
            {
                Val = -285745073
            };

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

            sdtPlaceholder2.Append(docPartReference2);

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

            SdtContentBlock sdtContentBlock2 = new SdtContentBlock();

            Paragraph paragraph5 = new Paragraph()
            {
                RsidParagraphAddition = "001E13C4", RsidParagraphProperties = "001E13C4", RsidRunAdditionDefault = "001E13C4"
            };

            Run  run5  = new Run();
            Text text4 = new Text();

            text4.Text = "Test b";

            run5.Append(text4);

            paragraph5.Append(run5);

            sdtContentBlock2.Append(paragraph5);

            sdtBlock2.Append(sdtProperties2);
            sdtBlock2.Append(sdtEndCharProperties2);
            sdtBlock2.Append(sdtContentBlock2);
            BookmarkEnd bookmarkEnd1 = new BookmarkEnd()
            {
                DisplacedByCustomXml = DisplacedByCustomXmlValues.Previous, Id = "0"
            };
            Paragraph paragraph6 = new Paragraph()
            {
                RsidParagraphAddition = "001E13C4", RsidRunAdditionDefault = "001E13C4"
            };

            SectionProperties sectionProperties1 = new SectionProperties()
            {
                RsidR = "001E13C4"
            };
            PageSize pageSize1 = new PageSize()
            {
                Width = (UInt32Value)11906U, Height = (UInt32Value)16838U
            };
            PageMargin pageMargin1 = new PageMargin()
            {
                Top = 1440, Right = (UInt32Value)1440U, Bottom = 1440, Left = (UInt32Value)1440U, Header = (UInt32Value)708U, Footer = (UInt32Value)708U, Gutter = (UInt32Value)0U
            };
            Columns columns1 = new Columns()
            {
                Space = "708"
            };
            DocGrid docGrid1 = new DocGrid()
            {
                LinePitch = 360
            };

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

            body1.Append(paragraph1);
            body1.Append(sdtBlock1);
            body1.Append(paragraph3);
            body1.Append(paragraph4);
            body1.Append(bookmarkStart1);
            body1.Append(sdtBlock2);
            body1.Append(bookmarkEnd1);
            body1.Append(paragraph6);
            body1.Append(sectionProperties1);

            document1.Append(body1);

            mainDocumentPart1.Document = document1;
        }
        public static void Fill(OpenXmlElement docNode, XmlElement macroListXml, WordprocessingDocument wdDoc)
        {
            /* Форматированный текст для встроенных элементов */
            IEnumerable <Paragraph> paragraphs = docNode.Elements <Paragraph>();

            foreach (Paragraph paragraph in paragraphs)
            {
                IEnumerable <SdtRun> sdtRuns = paragraph.Elements <SdtRun>();
                foreach (SdtRun sdtRun in sdtRuns)
                {
                    // Из SdtProperties взять Tag для идентификации Content Control
                    SdtProperties sdtProperties = sdtRun.GetFirstChild <SdtProperties>();
                    Tag           tag           = sdtProperties.GetFirstChild <Tag>();

                    // Найти в macroListXml Node макропеременной
                    String macroVarValue = FindMacroVar(macroListXml, tag.Val);

                    if (macroVarValue != null)
                    {
                        // Сохранить старый стиль Run
                        SdtContentRun  sdtContentRun = sdtRun.GetFirstChild <SdtContentRun>();
                        OpenXmlElement oldRunProps   = sdtContentRun.GetFirstChild <Run>().GetFirstChild <RunProperties>().CloneNode(true);

                        // Очистить Node Content Control
                        sdtContentRun.RemoveAllChildren();

                        // Создать новую Run Node
                        Run newRun = sdtContentRun.AppendChild(new Run());
                        // Вернуть старый стиль
                        newRun.AppendChild(oldRunProps);

                        // Вставить текст (без переносов строк!!!)
                        newRun.AppendChild(new Text(macroVarValue));
                    }
                }
            }

            /* Получить остальные Content Control */
            IEnumerable <SdtBlock> sdtBlocks = docNode.Elements <SdtBlock>();

            foreach (SdtBlock sdtBlock in sdtBlocks)
            {
                // Получить параметры(SdtProperties) Content Control
                SdtProperties sdtProperties = sdtBlock.GetFirstChild <SdtProperties>();

                // Получить Tag для идентификации Content Control
                Tag tag = sdtProperties.GetFirstChild <Tag>();

                // Получить значение макроперенной из macroListXml
                Console.WriteLine("Tag: " + tag.Val);
                String macroVarValue = FindMacroVar(macroListXml, tag.Val);

                // Если макропеременная есть в MacroListXml
                if (macroVarValue != null)
                {
                    Console.WriteLine("Value: " + macroVarValue);
                    // Получить блок содержимого Content Control
                    SdtContentBlock sdtContentBlock = sdtBlock.GetFirstChild <SdtContentBlock>();

                    /* Форматированный текст для абзацев */
                    if (sdtProperties.GetFirstChild <SdtPlaceholder>() != null && sdtContentBlock.GetFirstChild <Paragraph>() != null)
                    {
                        // Сохранить старый стиль параграфа
                        ParagraphProperties oldParagraphProperties = sdtContentBlock.GetFirstChild <Paragraph>().GetFirstChild <ParagraphProperties>().CloneNode(true) as ParagraphProperties;
                        String oldParagraphPropertiesXml           = oldParagraphProperties.InnerXml;

                        // Очистить ноду с контентом
                        sdtContentBlock.RemoveAllChildren();

                        InsertText(macroVarValue, oldParagraphPropertiesXml, sdtContentBlock);
                    }

                    /* Таблицы */
                    if (sdtProperties.GetFirstChild <SdtPlaceholder>() != null && sdtContentBlock.GetFirstChild <Table>() != null)
                    {
                        // Получить ноду таблицы
                        Table table = sdtContentBlock.GetFirstChild <Table>();

                        // Получить все строки таблицы
                        IEnumerable <TableRow> tableRows = table.Elements <TableRow>();

                        // Получить вторую строку из таблицы
                        TableRow tableRow     = tableRows.ElementAt(1) as TableRow;
                        Type     tableRowType = tableRow.GetType();

                        // Получить все стили столбцов
                        List <String> paragraphCellStyles       = new List <string>();
                        IEnumerable <OpenXmlElement> tableCells = tableRow.Elements <TableCell>();
                        foreach (OpenXmlElement tableCell in tableCells)
                        {
                            String paragraphCellStyleXml = tableCell.GetFirstChild <Paragraph>().GetFirstChild <ParagraphProperties>().InnerXml;
                            paragraphCellStyles.Add(paragraphCellStyleXml);
                        }

                        // Удалить все строки, после первой
                        while (tableRows.Count <TableRow>() > 1)
                        {
                            TableRow lastTableRows = tableRows.Last <TableRow>();
                            lastTableRows.Remove();
                        }

                        // Удалить последний элемент, если это не TableRow
                        OpenXmlElement lastNode = table.LastChild;
                        if (lastNode.GetType() != tableRowType)
                        {
                            lastNode.Remove();
                        }

                        string[] rowDelimiters    = new string[] { "|||" };
                        string[] columnDelimiters = new string[] { "^^^" };

                        // Получить массив строк из макропеременной
                        String[] rowsXml = macroVarValue.Split(rowDelimiters, StringSplitOptions.None);
                        int      i       = 0;
                        while (i < rowsXml.Length)
                        {
                            // Получить строку
                            String rowXml = rowsXml[i];

                            // Добавить ноду строки таблицы
                            TableRow newTableRow = table.AppendChild(new TableRow());

                            // Получить из строки массив ячеек
                            String[] cellsXml = rowXml.Split(columnDelimiters, StringSplitOptions.None);

                            int j = 0;
                            while (j < cellsXml.Length)
                            {
                                // Получить ячейку
                                String cellXml = cellsXml[j];

                                // Убрать символ CRLF в конце строки
                                cellXml = cellXml.TrimEnd(new char[] { '\n', '\r' });

                                // Добавить ноду ячейку в строку таблицы
                                TableCell newTableCell = newTableRow.AppendChild(new TableCell());

                                // Вставить текст
                                InsertText(cellXml, paragraphCellStyles[j], newTableCell);

                                j++;
                            }

                            i++;
                        }
                    }

                    /* Картинки */
                    if (sdtProperties.GetFirstChild <SdtContentPicture>() != null)
                    {
                        // Получить путь к файлу
                        String imageFilePath = macroVarValue;

                        // Получить расширение файла
                        String        extension = System.IO.Path.GetExtension(imageFilePath).ToLower();
                        ImagePartType imagePartType;
                        switch (extension)
                        {
                        case "jpeg":
                            imagePartType = ImagePartType.Jpeg;
                            break;

                        case "jpg":
                            imagePartType = ImagePartType.Jpeg;
                            break;

                        case "png":
                            imagePartType = ImagePartType.Png;
                            break;

                        case "bmp":
                            imagePartType = ImagePartType.Bmp;
                            break;

                        case "gif":
                            imagePartType = ImagePartType.Gif;
                            break;

                        default:
                            imagePartType = ImagePartType.Jpeg;
                            break;
                        }
                        ;

                        // Добавить ImagePart в документ
                        ImagePart imagePart = wdDoc.MainDocumentPart.AddImagePart(imagePartType);

                        // Получить картинку
                        using (FileStream stream = new FileStream(imageFilePath, FileMode.Open))
                        {
                            imagePart.FeedData(stream);
                        }

                        // Вычислить width и height
                        Bitmap    img         = new Bitmap(imageFilePath);
                        var       widthPx     = img.Width;
                        var       heightPx    = img.Height;
                        var       horzRezDpi  = img.HorizontalResolution;
                        var       vertRezDpi  = img.VerticalResolution;
                        const int emusPerInch = 914400;
                        const int emusPerCm   = 360000;
                        var       widthEmus   = (long)(widthPx / horzRezDpi * emusPerInch);
                        var       heightEmus  = (long)(heightPx / vertRezDpi * emusPerInch);

                        // Получить ID ImagePart
                        string relationShipId = wdDoc.MainDocumentPart.GetIdOfPart(imagePart);

                        Paragraph   paragraph   = sdtContentBlock.GetFirstChild <Paragraph>();
                        Run         run         = paragraph.GetFirstChild <Run>();
                        Drawing     drawing     = run.GetFirstChild <Drawing>();
                        Inline      inline      = drawing.GetFirstChild <Inline>();
                        Graphic     graphic     = inline.GetFirstChild <Graphic>();
                        GraphicData graphicData = graphic.GetFirstChild <GraphicData>();
                        Picture     pic         = graphicData.GetFirstChild <Picture>();
                        BlipFill    blipFill    = pic.GetFirstChild <BlipFill>();
                        Blip        blip        = blipFill.GetFirstChild <Blip>();

                        string prefix       = "r";
                        string localName    = "embed";
                        string namespaceUri = @"http://schemas.openxmlformats.org/officeDocument/2006/relationships";

                        OpenXmlAttribute oldEmbedAttribute = blip.GetAttribute("embed", namespaceUri);

                        IList <OpenXmlAttribute> attributes = blip.GetAttributes();

                        if (oldEmbedAttribute != null)
                        {
                            attributes.Remove(oldEmbedAttribute);
                        }

                        // Удалить хз что, выявлено практическим путем
                        blipFill.RemoveAllChildren <SourceRectangle>();

                        // Установить новую картинку
                        blip.SetAttribute(new OpenXmlAttribute(prefix, localName, namespaceUri, relationShipId));
                        blip.SetAttribute(new OpenXmlAttribute("cstate", "", "print"));

                        // Подогнать размеры
                        Extent extent = inline.GetFirstChild <Extent>();

                        OpenXmlAttribute oldCxExtent = extent.GetAttribute("cx", "");
                        if (oldCxExtent != null)
                        {
                            var maxWidthEmus = long.Parse(oldCxExtent.Value);
                            if (widthEmus > maxWidthEmus)
                            {
                                var ratio = (heightEmus * 1.0m) / widthEmus;
                                widthEmus  = maxWidthEmus;
                                heightEmus = (long)(widthEmus * ratio);
                            }

                            extent.GetAttributes().Remove(oldCxExtent);
                        }

                        OpenXmlAttribute oldCyExtent = extent.GetAttribute("cy", "");
                        if (oldCyExtent != null)
                        {
                            extent.GetAttributes().Remove(oldCyExtent);
                        }

                        extent.SetAttribute(new OpenXmlAttribute("cx", "", widthEmus.ToString()));
                        extent.SetAttribute(new OpenXmlAttribute("cy", "", heightEmus.ToString()));

                        ShapeProperties shapeProperties = pic.GetFirstChild <ShapeProperties>();
                        Transform2D     transform2D     = shapeProperties.GetFirstChild <Transform2D>();
                        Extents         extents         = transform2D.GetFirstChild <Extents>();

                        OpenXmlAttribute oldCxExtents = extents.GetAttribute("cx", "");
                        if (oldCxExtents != null)
                        {
                            extents.GetAttributes().Remove(oldCxExtents);
                        }

                        OpenXmlAttribute oldCyExtents = extents.GetAttribute("cy", "");
                        if (oldCyExtents != null)
                        {
                            extents.GetAttributes().Remove(oldCyExtents);
                        }

                        extents.SetAttribute(new OpenXmlAttribute("cx", "", widthEmus.ToString()));
                        extents.SetAttribute(new OpenXmlAttribute("cy", "", heightEmus.ToString()));

                        // Удалить placeholder
                        ShowingPlaceholder showingPlaceholder = sdtProperties.GetFirstChild <ShowingPlaceholder>();
                        if (showingPlaceholder != null)
                        {
                            sdtProperties.RemoveChild <ShowingPlaceholder>(showingPlaceholder);
                        }
                    }

                    /* Повторяющийся раздел */
                    if (sdtProperties.GetFirstChild <SdtRepeatedSection>() != null)
                    {
                        // Представить repeatedSection как новый xml документ (сделать корнем)
                        XmlDocument repeatedSectionXml = new XmlDocument();
                        repeatedSectionXml.LoadXml(macroVarValue);

                        // Получить корневой элемент repeatedSection
                        XmlElement rootRepeatedSectionXml = repeatedSectionXml.DocumentElement;

                        // Получить количество repeatedSectionItem
                        XmlNodeList repeatedSectionItems = rootRepeatedSectionXml.SelectNodes("repeatedSectionItem");
                        int         repeatedItemCount    = repeatedSectionItems.Count;

                        Console.WriteLine("Количество repeatedSectionItem: " + repeatedItemCount);

                        /* Блок клонирования ноды повтор. раздела до нужного количества */
                        for (int i = 0; i < repeatedItemCount; i++)
                        {
                            XmlElement macroListRepeatedSectionItem = rootRepeatedSectionXml.SelectSingleNode(String.Format(@"repeatedSectionItem[@id=""{0}""]", i)) as XmlElement;
                            Console.WriteLine("Item " + i + ": " + macroListRepeatedSectionItem.OuterXml);

                            SdtContentBlock sdtContentBlockRepeatedSectionItem = sdtContentBlock.Elements <SdtBlock>().Last <SdtBlock>().GetFirstChild <SdtContentBlock>();

                            Fill(sdtContentBlockRepeatedSectionItem, macroListRepeatedSectionItem, wdDoc);

                            if (i + 1 < repeatedItemCount)
                            {
                                SdtBlock clonedRepeatedSectionItem = sdtContentBlock.GetFirstChild <SdtBlock>().Clone() as SdtBlock;
                                sdtContentBlock.AppendChild <SdtBlock>(clonedRepeatedSectionItem);
                            }
                        }
                        /**/

                        //Fill(sdtContentBlock, macroListRepeatedSection, wdDoc);
                    }
                }

                Console.WriteLine();
            }
        }
Ejemplo n.º 11
0
        private void SetMultipleBlockContent(MainDocumentPart mainDocumentPart, string sdtBlockTag, string value)
        {
            List <SdtElement> SdtElementList = mainDocumentPart.Document.Descendants <SdtElement>().ToList();
            Regex             tagRegex       = new Regex(@"<[^>]+>");

            foreach (SdtElement sdtr in SdtElementList)
            {
                var s = sdtr.SdtProperties.GetFirstChild <Tag>().Val.Value;
                if (sdtr.SdtProperties.GetFirstChild <Tag>().Val.Value == sdtBlockTag)
                {
                    bool flag    = false;
                    bool hasTags = false;

                    if (sdtr.GetFirstChild <SdtContentRun>() != null)
                    {
                        OpenXmlElement     sdtc     = sdtr.GetFirstChild <SdtContentRun>();
                        OpenXmlElementList elements = sdtc.ChildElements;

                        var mySdtc = new SdtContentBlock(sdtc.OuterXml);

                        foreach (OpenXmlElement elem in elements)
                        {
                            if (elem.HasChildren && !flag)
                            {
                                if (elem.ChildElements.OfType <Text>().ElementAt(0).Text.Contains("☐"))
                                {
                                    if (value.Equals("True") || value.Equals("true"))
                                    {
                                        elem.ChildElements.OfType <Text>().ElementAt(0).Text = "☒";
                                    }

                                    else
                                    {
                                        elem.ChildElements.OfType <Text>().ElementAt(0).Text = "☐";
                                    }
                                }
                                else if (elem.ChildElements.OfType <Text>().ElementAt(0).Text.Contains("☒"))
                                {
                                    if (value.Equals("True") || value.Equals("true"))
                                    {
                                        elem.ChildElements.OfType <Text>().ElementAt(0).Text = "☒";
                                    }

                                    else
                                    {
                                        elem.ChildElements.OfType <Text>().ElementAt(0).Text = "☐";
                                    }
                                }
                                else if (elem.ChildElements.OfType <Text>().ElementAt(0).Text.Contains("○"))
                                {
                                    if (value.Equals("True") || value.Equals("true"))
                                    {
                                        elem.ChildElements.OfType <Text>().ElementAt(0).Text = "●";
                                    }

                                    else
                                    {
                                        elem.ChildElements.OfType <Text>().ElementAt(0).Text = "○";
                                    }
                                }
                                else if (elem.ChildElements.OfType <Text>().ElementAt(0).Text.Contains("●"))
                                {
                                    if (value.Equals("True") || value.Equals("true"))
                                    {
                                        elem.ChildElements.OfType <Text>().ElementAt(0).Text = "●";
                                    }

                                    else
                                    {
                                        elem.ChildElements.OfType <Text>().ElementAt(0).Text = "○";
                                    }
                                }
                                else
                                {
                                    if (value != null && value.Contains("\n"))
                                    {
                                        hasTags = tagRegex.IsMatch(value);
                                        if (hasTags)
                                        {
                                            elem.ChildElements.OfType <Text>().ElementAt(0).Text = "";
                                            SetHtml(mainDocumentPart, sdtBlockTag, value, elem);
                                        }
                                        else
                                        {
                                            string[] val = Regex.Split(value, "\n");
                                            elem.ChildElements.OfType <Text>().ElementAt(0).Text = "";
                                            for (int i = 0; i < val.Count(); i++)
                                            {
                                                elem.AppendChild(new Text(val[i]));
                                                if (i != (val.Count() - 1))
                                                {
                                                    elem.AppendChild(new Break());
                                                }
                                            }
                                        }
                                        flag = true;
                                    }
                                    else
                                    {
                                        hasTags = tagRegex.IsMatch(value);
                                        if (hasTags)
                                        {
                                            elem.ChildElements.OfType <Text>().ElementAt(0).Text = "";
                                            SetHtml(mainDocumentPart, sdtBlockTag, value, elem);
                                        }
                                        else
                                        {
                                            elem.ChildElements.OfType <Text>().ElementAt(0).Text = value;
                                        }
                                        flag = true;
                                    }
                                    break;
                                }
                            }
                            else if (elem.HasChildren && flag)
                            {
                                elem.ChildElements.OfType <Text>().ElementAt(0).Text = "";
                            }
                        }
                    }
                    else if (sdtr.GetFirstChild <SdtContentBlock>() != null)
                    {
                        OpenXmlElement     sdtc     = sdtr.GetFirstChild <SdtContentBlock>();
                        OpenXmlElementList elements = sdtc.ChildElements;

                        var mySdtc = new SdtContentBlock(sdtc.OuterXml);

                        foreach (OpenXmlElement elem in elements)
                        {
                            if (elem.HasChildren && !flag)
                            {
                                if (elem.ChildElements.OfType <Run>().ElementAt(0).ChildElements.OfType <Text>().ElementAt(0).Text.Contains("☐"))
                                {
                                    if (value.Equals("True") || value.Equals("true"))
                                    {
                                        elem.ChildElements.OfType <Run>().ElementAt(0).ChildElements.OfType <Text>().ElementAt(0).Text = "☒";
                                    }
                                    else
                                    {
                                        elem.ChildElements.OfType <Run>().ElementAt(0).ChildElements.OfType <Text>().ElementAt(0).Text = "☐";
                                    }
                                }
                                else if (elem.ChildElements.OfType <Run>().ElementAt(0).ChildElements.OfType <Text>().ElementAt(0).Text.Contains("☒"))
                                {
                                    if (value.Equals("True") || value.Equals("true"))
                                    {
                                        elem.ChildElements.OfType <Run>().ElementAt(0).ChildElements.OfType <Text>().ElementAt(0).Text = "☒";
                                    }
                                    else
                                    {
                                        elem.ChildElements.OfType <Run>().ElementAt(0).ChildElements.OfType <Text>().ElementAt(0).Text = "☐";
                                    }
                                }

                                else if (elem.ChildElements.OfType <Run>().ElementAt(0).ChildElements.OfType <Text>().ElementAt(0).Text.Contains("○"))
                                {
                                    if (value.Equals("True") || value.Equals("true"))
                                    {
                                        elem.ChildElements.OfType <Run>().ElementAt(0).ChildElements.OfType <Text>().ElementAt(0).Text = "●";
                                    }
                                    else
                                    {
                                        elem.ChildElements.OfType <Run>().ElementAt(0).ChildElements.OfType <Text>().ElementAt(0).Text = "○";
                                    }
                                }
                                else if (elem.ChildElements.OfType <Run>().ElementAt(0).ChildElements.OfType <Text>().ElementAt(0).Text.Contains("●"))
                                {
                                    if (value.Equals("True") || value.Equals("true"))
                                    {
                                        elem.ChildElements.OfType <Run>().ElementAt(0).ChildElements.OfType <Text>().ElementAt(0).Text = "●";
                                    }
                                    else
                                    {
                                        elem.ChildElements.OfType <Run>().ElementAt(0).ChildElements.OfType <Text>().ElementAt(0).Text = "○";
                                    }
                                }

                                else
                                {
                                    if (value.Contains("\n"))
                                    {
                                        hasTags = tagRegex.IsMatch(value);
                                        if (hasTags)
                                        {
                                            elem.ChildElements.OfType <Run>().ElementAt(0).ChildElements.OfType <Text>().ElementAt(0).Text = "";
                                            SetHtml(mainDocumentPart, sdtBlockTag, value, elem);
                                        }
                                        else
                                        {
                                            string[] val = Regex.Split(value, "\n");
                                            elem.ChildElements.OfType <Run>().ElementAt(0).ChildElements.OfType <Text>().ElementAt(0).Text = "";
                                            for (int i = 0; i < val.Count(); i++)
                                            {
                                                elem.AppendChild(new Text(val[i]));
                                                if (i != (val.Count() - 1))
                                                {
                                                    elem.AppendChild(new Break());
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        hasTags = tagRegex.IsMatch(value);
                                        if (hasTags)
                                        {
                                            elem.ChildElements.OfType <Run>().ElementAt(0).ChildElements.OfType <Text>().ElementAt(0).Text = "";
                                            SetHtml(mainDocumentPart, sdtBlockTag, value, elem);
                                        }
                                        else
                                        {
                                            elem.ChildElements.OfType <Run>().ElementAt(0).ChildElements.OfType <Text>().ElementAt(0).Text = value;
                                        }
                                        flag = true;
                                    }
                                    break;
                                }
                            }
                            else if (elem.HasChildren && flag)
                            {
                                elem.ChildElements.OfType <Run>().ElementAt(0).ChildElements.OfType <Text>().ElementAt(0).Text = "";
                            }
                        }
                    }

                    else if (sdtr.GetFirstChild <SdtContentCell>() != null)
                    {
                        OpenXmlElement     sdtc     = sdtr.GetFirstChild <SdtContentCell>();
                        OpenXmlElementList elements = sdtc.ChildElements;

                        var mySdtc = new SdtContentBlock(sdtc.OuterXml);

                        foreach (OpenXmlElement elem in elements)
                        {
                            if (elem.HasChildren && !flag)
                            {
                                if (elem.ChildElements.OfType <Paragraph>().ElementAt(0).ChildElements.OfType <Run>().ElementAt(0).ChildElements.OfType <Text>().ElementAt(0).Text.Contains("☐"))
                                {
                                    if (value.Equals("True") || value.Equals("true"))
                                    {
                                        elem.ChildElements.OfType <Paragraph>().ElementAt(0).ChildElements.OfType <Run>().ElementAt(0).ChildElements.OfType <Text>().ElementAt(0).Text = "☒";
                                    }

                                    else
                                    {
                                        elem.ChildElements.OfType <Paragraph>().ElementAt(0).ChildElements.OfType <Run>().ElementAt(0).ChildElements.OfType <Text>().ElementAt(0).Text = "☐";
                                    }
                                }
                                else if (elem.ChildElements.OfType <Paragraph>().ElementAt(0).ChildElements.OfType <Run>().ElementAt(0).ChildElements.OfType <Text>().ElementAt(0).Text.Contains("☒"))
                                {
                                    if (value.Equals("True") || value.Equals("true"))
                                    {
                                        elem.ChildElements.OfType <Paragraph>().ElementAt(0).ChildElements.OfType <Run>().ElementAt(0).ChildElements.OfType <Text>().ElementAt(0).Text = "☒";
                                    }

                                    else
                                    {
                                        elem.ChildElements.OfType <Paragraph>().ElementAt(0).ChildElements.OfType <Run>().ElementAt(0).ChildElements.OfType <Text>().ElementAt(0).Text = "☐";
                                    }
                                }

                                else if (elem.ChildElements.OfType <Paragraph>().ElementAt(0).ChildElements.OfType <Run>().ElementAt(0).ChildElements.OfType <Text>().ElementAt(0).Text.Contains("○"))
                                {
                                    if (value.Equals("True") || value.Equals("true"))
                                    {
                                        elem.ChildElements.OfType <Paragraph>().ElementAt(0).ChildElements.OfType <Run>().ElementAt(0).ChildElements.OfType <Text>().ElementAt(0).Text = "●";
                                    }

                                    else
                                    {
                                        elem.ChildElements.OfType <Paragraph>().ElementAt(0).ChildElements.OfType <Run>().ElementAt(0).ChildElements.OfType <Text>().ElementAt(0).Text = "○";
                                    }
                                }
                                else if (elem.ChildElements.OfType <Paragraph>().ElementAt(0).ChildElements.OfType <Run>().ElementAt(0).ChildElements.OfType <Text>().ElementAt(0).Text.Contains("●"))
                                {
                                    if (value.Equals("True") || value.Equals("true"))
                                    {
                                        elem.ChildElements.OfType <Paragraph>().ElementAt(0).ChildElements.OfType <Run>().ElementAt(0).ChildElements.OfType <Text>().ElementAt(0).Text = "●";
                                    }

                                    else
                                    {
                                        elem.ChildElements.OfType <Paragraph>().ElementAt(0).ChildElements.OfType <Run>().ElementAt(0).ChildElements.OfType <Text>().ElementAt(0).Text = "○";
                                    }
                                }

                                else
                                {
                                    if (value.Contains("\n"))
                                    {
                                        hasTags = tagRegex.IsMatch(value);
                                        if (hasTags)
                                        {
                                            elem.ChildElements.OfType <Paragraph>().ElementAt(0).ChildElements.OfType <Run>().ElementAt(0).ChildElements.OfType <Text>().ElementAt(0).Text = "";
                                            elem.RemoveAllChildren <Paragraph>();
                                            SetHtml(mainDocumentPart, sdtBlockTag, value, elem);
                                        }
                                        else
                                        {
                                            string[] val = Regex.Split(value, "\n");
                                            elem.ChildElements.OfType <Paragraph>().ElementAt(0).ChildElements.OfType <Run>().ElementAt(0).ChildElements.OfType <Text>().ElementAt(0).Text = "";
                                            for (int i = 0; i < val.Count(); i++)
                                            {
                                                elem.ChildElements.OfType <Paragraph>().ElementAt(0).ChildElements.OfType <Run>().ElementAt(0).AppendChild(new Text(val[i]));

                                                if (i != (val.Count() - 1))
                                                {
                                                    elem.ChildElements.OfType <Paragraph>().ElementAt(0).ChildElements.OfType <Run>().ElementAt(0).AppendChild(new Break());
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        if (value.Contains("\n"))
                                        {
                                            hasTags = tagRegex.IsMatch(value);
                                            if (hasTags)
                                            {
                                                elem.ChildElements.OfType <Paragraph>().ElementAt(0).ChildElements.OfType <Run>().ElementAt(0).ChildElements.OfType <Text>().ElementAt(0).Text = "";
                                                elem.RemoveAllChildren <Paragraph>();
                                                SetHtml(mainDocumentPart, sdtBlockTag, value, elem);
                                            }
                                            else
                                            {
                                                string[] val = Regex.Split(value, "\n");
                                                elem.ChildElements.OfType <Paragraph>().ElementAt(0).ChildElements.OfType <Run>().ElementAt(0).ChildElements.OfType <Text>().ElementAt(0).Text = "";
                                                for (int i = 0; i < val.Count(); i++)
                                                {
                                                    elem.AppendChild(new Text(val[i]));
                                                    if (i != (val.Count() - 1))
                                                    {
                                                        elem.AppendChild(new Break());
                                                    }
                                                }
                                            }
                                        }
                                        else
                                        {
                                            hasTags = tagRegex.IsMatch(value);
                                            if (hasTags)
                                            {
                                                elem.ChildElements.OfType <Paragraph>().ElementAt(0).ChildElements.OfType <Run>().ElementAt(0).ChildElements.OfType <Text>().ElementAt(0).Text = "";
                                                elem.RemoveAllChildren <Paragraph>();
                                                SetHtml(mainDocumentPart, sdtBlockTag, value, elem);
                                            }
                                            else
                                            {
                                                elem.ChildElements.OfType <Paragraph>().ElementAt(0).ChildElements.OfType <Run>().ElementAt(0).ChildElements.OfType <Text>().ElementAt(0).Text = value;
                                            }
                                            flag = true;
                                        }
                                        break;
                                    }
                                    break;
                                }
                            }
                            else if (elem.HasChildren && flag)
                            {
                                elem.ChildElements.OfType <Paragraph>().ElementAt(0).ChildElements.OfType <Run>().ElementAt(0).ChildElements.OfType <Text>().ElementAt(0).Text = "";
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 12
0
        private void GenerateFooterPartContent(FooterPart footerPart1)
        {
            Footer footer1 = new Footer();

            SdtBlock sdtBlock1 = new SdtBlock();

            SdtProperties sdtProperties1 = new SdtProperties();
            SdtId         sdtId1         = new SdtId()
            {
                Val = 712706661
            };

            SdtContentDocPartObject sdtContentDocPartObject1 = new SdtContentDocPartObject();
            DocPartGallery          docPartGallery1          = new DocPartGallery()
            {
                Val = "Page Numbers (Bottom of Page)"
            };
            DocPartUnique docPartUnique1 = new DocPartUnique();

            sdtContentDocPartObject1.Append(docPartGallery1);
            sdtContentDocPartObject1.Append(docPartUnique1);

            sdtProperties1.Append(sdtId1);
            sdtProperties1.Append(sdtContentDocPartObject1);

            SdtEndCharProperties sdtEndCharProperties1 = new SdtEndCharProperties();

            RunProperties runProperties1 = new RunProperties();
            NoProof       noProof1       = new NoProof();

            runProperties1.Append(noProof1);

            sdtEndCharProperties1.Append(runProperties1);

            SdtContentBlock sdtContentBlock1 = new SdtContentBlock();

            Paragraph paragraph1 = new Paragraph();

            ParagraphProperties paragraphProperties1 = new ParagraphProperties();
            ParagraphStyleId    paragraphStyleId1    = new ParagraphStyleId()
            {
                Val = "Footer"
            };
            Justification justification1 = new Justification()
            {
                Val = JustificationValues.Center
            };

            paragraphProperties1.Append(paragraphStyleId1);
            paragraphProperties1.Append(justification1);

            Run       run1       = new Run();
            FieldChar fieldChar1 = new FieldChar()
            {
                FieldCharType = FieldCharValues.Begin
            };

            run1.Append(fieldChar1);

            Run       run2       = new Run();
            FieldCode fieldCode1 = new FieldCode()
            {
                Space = SpaceProcessingModeValues.Preserve
            };

            fieldCode1.Text = " PAGE   \\* MERGEFORMAT ";

            run2.Append(fieldCode1);

            Run       run3       = new Run();
            FieldChar fieldChar2 = new FieldChar()
            {
                FieldCharType = FieldCharValues.Separate
            };

            run3.Append(fieldChar2);

            Run run4 = new Run();

            RunProperties runProperties2 = new RunProperties();
            NoProof       noProof2       = new NoProof();

            runProperties2.Append(noProof2);
            Text text1 = new Text();

            text1.Text = "1";

            run4.Append(runProperties2);
            run4.Append(text1);

            Run run5 = new Run();

            RunProperties runProperties3 = new RunProperties();
            NoProof       noProof3       = new NoProof();

            runProperties3.Append(noProof3);
            FieldChar fieldChar3 = new FieldChar()
            {
                FieldCharType = FieldCharValues.End
            };

            run5.Append(runProperties3);
            run5.Append(fieldChar3);

            paragraph1.Append(paragraphProperties1);
            paragraph1.Append(run1);
            paragraph1.Append(run2);
            paragraph1.Append(run3);
            paragraph1.Append(run4);
            paragraph1.Append(run5);

            sdtContentBlock1.Append(paragraph1);

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

            Paragraph paragraph2 = new Paragraph();

            ParagraphProperties paragraphProperties2 = new ParagraphProperties();
            ParagraphStyleId    paragraphStyleId2    = new ParagraphStyleId()
            {
                Val = "Footer"
            };

            paragraphProperties2.Append(paragraphStyleId2);

            paragraph2.Append(paragraphProperties2);

            footer1.Append(sdtBlock1);
            footer1.Append(paragraph2);

            footerPart1.Footer = footer1;
        }
Ejemplo n.º 13
0
        public void Process(Body Body, OpenXmlElement Element)
        {
            string InnerText = Element.InnerText;

            if (VerifyCodeToken(ref InnerText))
            {
                Element.Remove();
                Scripting.Eval(InnerText);
                return;
            }

            if (Scripting.CaptureElement(Body, Element))
            {
                Element.Remove();
                return;
            }

            if (string.IsNullOrEmpty(InnerText))
            {
                return;
            }

            if (VerifyToken(ref InnerText, out TokenParameters TokenParams))
            {
                DataType DataType = Data.GetObject(InnerText, TokenParams, out object Obj);

                if (DataType == DataType.None)
                {
                    throw new Exception(string.Format("Could not find data for token '{0}'", InnerText));
                }

                if ((CurrentRun = Element.GetFirstChild <RunProperties>()) == null)
                {
                    SdtProperties SdtProps = Element.GetFirstChild <SdtProperties>();

                    if (SdtProps != null)
                    {
                        CurrentRun = SdtProps.GetFirstChild <RunProperties>();
                    }
                }


                if (Element is SdtContentBlock SdtContentBlock)
                {
                    OpenXmlElement NewContent = GenerateContent(Body, DataType, Obj, TokenParams);

                    // TODO: Non existant template token, do something?
                    if (NewContent == null)
                    {
                        throw new NotImplementedException();
                    }

                    if (NewContent is Run)
                    {
                        NewContent = new Paragraph(new ParagraphProperties(), NewContent);
                    }

                    if (DataType == DataType.PageBreak)
                    {
                        SdtContentBlock.Parent.Parent.ReplaceChild(NewContent, SdtContentBlock.Parent);
                    }
                    else
                    {
                        SdtContentBlock NewBlock = new SdtContentBlock();
                        NewBlock.AppendChild(NewContent);

                        SdtContentBlock.Parent.ReplaceChild(NewBlock, SdtContentBlock);
                    }
                    return;
                }
                else if (Element is SdtContentRun SdtContentRun)
                {
                    // if (SdtRun) seems to replace this part?
                    throw new NotImplementedException();
                }
                else if (Element is SdtRun SdtRun)
                {
                    OpenXmlElement NewContent = GenerateContent(Body, DataType, Obj, TokenParams);

                    // TODO: Non existant template token, do something?
                    if (NewContent == null)
                    {
                        throw new NotImplementedException();
                    }

                    if (NewContent is Table && ParentsAreElement <Paragraph>(SdtRun, out OpenXmlElement FoundParent))
                    {
                        FoundParent.Parent.ReplaceChild(NewContent, FoundParent);
                        return;
                    }

                    Element.Parent.ReplaceChild(NewContent, SdtRun);
                    return;
                }
            }

            // Array is used here because element children are dynamically changed, IEnumerable may have side effects
            OpenXmlElement[] Elements = Element.Elements().ToArray();
            for (int i = 0; i < Elements.Length; i++)
            {
                OpenXmlElement E = Elements[i];

                if (E is Table T)
                {
                    ProcessTable(Body, T);
                }
                else
                {
                    Process(Body, E);
                }
            }
        }