コード例 #1
0
        public void PlaceholderBuildingBlock(bool isShowingPlaceholderText)
        {
            //ExStart
            //ExFor:StructuredDocumentTag.IsShowingPlaceholderText
            //ExFor:StructuredDocumentTag.Placeholder
            //ExFor:StructuredDocumentTag.PlaceholderName
            //ExSummary:Shows how to use a building block's contents as a custom placeholder text for a structured document tag.
            Document doc = new Document();

            // Insert a plain text structured document tag of the "PlainText" type, which will function as a text box.
            // The contents that it will display by default are a "Click here to enter text." prompt.
            StructuredDocumentTag tag = new StructuredDocumentTag(doc, SdtType.PlainText, MarkupLevel.Inline);

            // We can get the tag to display the contents of a building block instead of the default text.
            // First, add a building block with contents to the glossary document.
            GlossaryDocument glossaryDoc = doc.GlossaryDocument;

            BuildingBlock substituteBlock = new BuildingBlock(glossaryDoc);

            substituteBlock.Name = "Custom Placeholder";
            substituteBlock.AppendChild(new Section(glossaryDoc));
            substituteBlock.FirstSection.AppendChild(new Body(glossaryDoc));
            substituteBlock.FirstSection.Body.AppendParagraph("Custom placeholder text.");

            glossaryDoc.AppendChild(substituteBlock);

            // Then, use the structured document tag's "PlaceholderName" property to reference that building block by name.
            tag.PlaceholderName = "Custom Placeholder";

            // If "PlaceholderName" refers to an existing block in the parent document's glossary document,
            // we will be able to verify the building block via the "Placeholder" property.
            Assert.AreEqual(substituteBlock, tag.Placeholder);

            // Set the "IsShowingPlaceholderText" property to "true" to treat the
            // structured document tag's current contents as placeholder text.
            // This means that clicking on the text box in Microsoft Word will immediately highlight all the tag's contents.
            // Set the "IsShowingPlaceholderText" property to "false" to get the
            // structured document tag to treat its contents as text that a user has already entered.
            // Clicking on this text in Microsoft Word will place the blinking cursor at the clicked location.
            tag.IsShowingPlaceholderText = isShowingPlaceholderText;

            DocumentBuilder builder = new DocumentBuilder(doc);

            builder.InsertNode(tag);

            doc.Save(ArtifactsDir + "StructuredDocumentTag.PlaceholderBuildingBlock.docx");
            //ExEnd

            doc             = new Document(ArtifactsDir + "StructuredDocumentTag.PlaceholderBuildingBlock.docx");
            tag             = (StructuredDocumentTag)doc.GetChild(NodeType.StructuredDocumentTag, 0, true);
            substituteBlock = (BuildingBlock)doc.GlossaryDocument.GetChild(NodeType.BuildingBlock, 0, true);

            Assert.AreEqual("Custom Placeholder", substituteBlock.Name);
            Assert.AreEqual(isShowingPlaceholderText, tag.IsShowingPlaceholderText);
            Assert.AreEqual(substituteBlock, tag.Placeholder);
            Assert.AreEqual(substituteBlock.Name, tag.PlaceholderName);
        }
コード例 #2
0
        [Test] //ExSkip
        public void GlossaryDocument()
        {
            Document doc = new Document();

            GlossaryDocument glossaryDoc = new GlossaryDocument();

            glossaryDoc.AppendChild(new BuildingBlock(glossaryDoc)
            {
                Name = "Block 1"
            });
            glossaryDoc.AppendChild(new BuildingBlock(glossaryDoc)
            {
                Name = "Block 2"
            });
            glossaryDoc.AppendChild(new BuildingBlock(glossaryDoc)
            {
                Name = "Block 3"
            });
            glossaryDoc.AppendChild(new BuildingBlock(glossaryDoc)
            {
                Name = "Block 4"
            });
            glossaryDoc.AppendChild(new BuildingBlock(glossaryDoc)
            {
                Name = "Block 5"
            });

            Assert.AreEqual(5, glossaryDoc.BuildingBlocks.Count);

            doc.GlossaryDocument = glossaryDoc;

            // There is a different ways how to get created building blocks
            Assert.AreEqual("Block 1", glossaryDoc.FirstBuildingBlock.Name);
            Assert.AreEqual("Block 2", glossaryDoc.BuildingBlocks[1].Name);
            Assert.AreEqual("Block 3", glossaryDoc.BuildingBlocks.ToArray()[2].Name);
            Assert.AreEqual("Block 5", glossaryDoc.LastBuildingBlock.Name);

            // Get a block by gallery, category and name
            BuildingBlock block4 =
                glossaryDoc.GetBuildingBlock(BuildingBlockGallery.All, "(Empty Category)", "Block 4");

            // All GUIDs are the same by default
            Assert.AreEqual("00000000-0000-0000-0000-000000000000", block4.Guid.ToString());

            // To be able to uniquely identify blocks by GUID, each GUID must be unique
            // We will do that using a custom visitor
            GlossaryDocVisitor visitor = new GlossaryDocVisitor();

            glossaryDoc.Accept(visitor);

            Assert.AreEqual(5, visitor.GetDictionary().Count);

            Console.WriteLine(visitor.GetText());

            // We can find our new blocks in Microsoft Word via Insert > Quick Parts > Building Blocks Organizer...
            doc.Save(MyDir + @"\Artifacts\BuildingBlocks.GlossaryDocument.dotx");
        }
コード例 #3
0
        public void InsertAutoText(string SignatureName)
        {
            const string NEW_DOCUMENT_NAME = "Sample AutoText Insert.docx";
            string       oldrelIDPic       = "";

            DocumentFormat.OpenXml.Drawing.Blip imgblip;
            using (WordprocessingDocument sampleDocument = WordprocessingDocument.Create(pathnewdoc + NEW_DOCUMENT_NAME, WordprocessingDocumentType.Document))
                using (WordprocessingDocument wrdTemplate = WordprocessingDocument.Open(pathtemplatedoc + TEMPLATE_NAME, false))
                {
                    MainDocumentPart mdp = sampleDocument.AddMainDocumentPart();
                    mdp.Document = new Document(new Body());

                    GlossaryDocumentPart gDocPart = wrdTemplate.MainDocumentPart.GetPartsOfType <GlossaryDocumentPart>().FirstOrDefault();
                    if (gDocPart != null)
                    {
                        GlossaryDocument gDoc = gDocPart.GlossaryDocument;
                        if (gDoc != null)
                        {
                            Console.WriteLine("AutoText Entries!");
                            foreach (DocPart entry in gDoc.DocParts)
                            {
                                if (entry.DocPartProperties.Category.Gallery.Val == DocPartGalleryValues.AutoText &&
                                    entry.DocPartProperties.DocPartName.Val == SignatureName)
                                {
                                    Console.WriteLine("Entry Name ==> {0}", entry.DocPartProperties.DocPartName.Val);
                                    Console.WriteLine(entry.DocPartBody.InnerXml);
                                    int paracount = entry.DocPartBody.Descendants <Paragraph>().Count();
                                    Console.WriteLine("Count of paragraphs ==> {0}", paracount);
                                    foreach (Paragraph entrypara in entry.DocPartBody.Descendants <Paragraph>())
                                    {
                                        // Let's get the relationship ID if it's there
                                        int PicCount = entrypara.Descendants <DocumentFormat.OpenXml.Drawing.Blip>().Count();
                                        if (PicCount > 0)
                                        {
                                            imgblip     = entrypara.Descendants <DocumentFormat.OpenXml.Drawing.Blip>().FirstOrDefault();
                                            oldrelIDPic = imgblip.Embed.Value;
                                            Console.WriteLine("Old Relationship ID ==> {0}", oldrelIDPic);
                                            imgblip.Embed.Value = "rId10";
                                            Console.WriteLine(imgblip.Embed.Value);

                                            ImagePart newSigImg = mdp.AddImagePart(ImagePartType.Png, imgblip.Embed.Value);
                                            mdp.CreateRelationshipToPart(newSigImg, imgblip.Embed.Value);
                                            newSigImg.FeedData(gDocPart.GetPartById(oldrelIDPic).GetStream());
                                        }
                                        mdp.Document.Body.AppendChild <Paragraph>(new Paragraph(entrypara.OuterXml));
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("No Glossary Document Part (AutoText Entries) found.");
                    }
                }
        }
コード例 #4
0
        [Test] //ExSkip
        public void GlossaryDocument()
        {
            Document         doc         = new Document();
            GlossaryDocument glossaryDoc = new GlossaryDocument();

            glossaryDoc.AppendChild(new BuildingBlock(glossaryDoc)
            {
                Name = "Block 1"
            });
            glossaryDoc.AppendChild(new BuildingBlock(glossaryDoc)
            {
                Name = "Block 2"
            });
            glossaryDoc.AppendChild(new BuildingBlock(glossaryDoc)
            {
                Name = "Block 3"
            });
            glossaryDoc.AppendChild(new BuildingBlock(glossaryDoc)
            {
                Name = "Block 4"
            });
            glossaryDoc.AppendChild(new BuildingBlock(glossaryDoc)
            {
                Name = "Block 5"
            });

            Assert.AreEqual(5, glossaryDoc.BuildingBlocks.Count);

            doc.GlossaryDocument = glossaryDoc;

            // There are various ways of accessing building blocks.
            // 1 -  Get the first/last building blocks in the collection:
            Assert.AreEqual("Block 1", glossaryDoc.FirstBuildingBlock.Name);
            Assert.AreEqual("Block 5", glossaryDoc.LastBuildingBlock.Name);

            // 2 -  Get a building block by index:
            Assert.AreEqual("Block 2", glossaryDoc.BuildingBlocks[1].Name);
            Assert.AreEqual("Block 3", glossaryDoc.BuildingBlocks.ToArray()[2].Name);

            // 3 -  Get the first building block that matches a gallery, name and category:
            Assert.AreEqual("Block 4",
                            glossaryDoc.GetBuildingBlock(BuildingBlockGallery.All, "(Empty Category)", "Block 4").Name);

            // We will do that using a custom visitor,
            // which will give every BuildingBlock in the GlossaryDocument a unique GUID
            GlossaryDocVisitor visitor = new GlossaryDocVisitor();

            glossaryDoc.Accept(visitor);
            Assert.AreEqual(5, visitor.GetDictionary().Count); //ExSkip

            Console.WriteLine(visitor.GetText());

            // When we open this document using Microsoft Word,
            // we can find the building blocks via Insert -> Quick Parts -> Building Blocks Organizer.
            doc.Save(ArtifactsDir + "BuildingBlocks.GlossaryDocument.dotx");
        }
コード例 #5
0
        public void PlaceholderBuildingBlock()
        {
            //ExStart
            //ExFor:StructuredDocumentTag.IsShowingPlaceholderText
            //ExFor:StructuredDocumentTag.Placeholder
            //ExFor:StructuredDocumentTag.PlaceholderName
            //ExSummary:Shows how to use the contents of a BuildingBlock as a custom placeholder text for a StructuredDocumentTag.
            Document doc = new Document();

            // Insert a plain text StructuredDocumentTag of the PlainText type, which will function like a text box
            // It contains a default "Click here to enter text." prompt, which we can click and replace with our own text
            StructuredDocumentTag tag = new StructuredDocumentTag(doc, SdtType.PlainText, MarkupLevel.Inline);

            // We can substitute that default placeholder with a custom phrase, which will be drawn from a BuildingBlock
            // First, we will need to create the BuildingBlock, give it content and add it to the GlossaryDocument
            GlossaryDocument glossaryDoc = doc.GlossaryDocument;

            BuildingBlock substituteBlock = new BuildingBlock(glossaryDoc);

            substituteBlock.Name = "Custom Placeholder";
            substituteBlock.AppendChild(new Section(glossaryDoc));
            substituteBlock.FirstSection.AppendChild(new Body(glossaryDoc));
            substituteBlock.FirstSection.Body.AppendParagraph("Custom placeholder text.");

            glossaryDoc.AppendChild(substituteBlock);

            // The substitute BuildingBlock we made can be referenced by name
            tag.PlaceholderName = "Custom Placeholder";

            // If PlaceholderName refers to an existing block in the parent document's GlossaryDocument,
            // the BuildingBlock will be automatically found and assigned to the Placeholder attribute
            Assert.AreEqual(substituteBlock, tag.Placeholder);

            // Setting this to true will register the text inside the StructuredDocumentTag as placeholder text
            // This means that, in Microsoft Word, all the text contents of the StructuredDocumentTag will be highlighted with one click,
            // so we can immediately replace the entire substitute text by typing
            // If this is false, the text will behave like an ordinary Paragraph and a cursor will be placed with nothing highlighted
            tag.IsShowingPlaceholderText = true;

            // Insert the StructuredDocumentTag into the document using a DocumentBuilder and save the document to a file
            DocumentBuilder builder = new DocumentBuilder(doc);

            builder.InsertNode(tag);

            doc.Save(ArtifactsDir + "StructuredDocumentTag.PlaceholderBuildingBlock.docx");
            //ExEnd

            doc             = new Document(ArtifactsDir + "StructuredDocumentTag.PlaceholderBuildingBlock.docx");
            tag             = (StructuredDocumentTag)doc.GetChild(NodeType.StructuredDocumentTag, 0, true);
            substituteBlock = (BuildingBlock)doc.GlossaryDocument.GetChild(NodeType.BuildingBlock, 0, true);

            Assert.AreEqual("Custom Placeholder", substituteBlock.Name);
            Assert.True(tag.IsShowingPlaceholderText);
            Assert.AreEqual(substituteBlock, tag.Placeholder);
            Assert.AreEqual(substituteBlock.Name, tag.PlaceholderName);
        }
コード例 #6
0
        [Test] //ExSkip
        public void BuildingBlockFields()
        {
            Document doc = new Document();

            // BuildingBlocks live inside the glossary document
            // If you're making a document from scratch, the glossary document must also be manually created
            GlossaryDocument glossaryDoc = new GlossaryDocument();

            doc.GlossaryDocument = glossaryDoc;

            // Create a building block and name it
            BuildingBlock block = new BuildingBlock(glossaryDoc);

            block.Name = "Custom Block";

            // Put in in the document's glossary document
            glossaryDoc.AppendChild(block);
            Assert.AreEqual(1, glossaryDoc.Count);

            // All GUIDs are this value by default
            Assert.AreEqual("00000000-0000-0000-0000-000000000000", block.Guid.ToString());

            // In Microsoft Word, we can use these attributes to find blocks in Insert > Quick Parts > Building Blocks Organizer
            Assert.AreEqual("(Empty Category)", block.Category);
            Assert.AreEqual(BuildingBlockType.None, block.Type);
            Assert.AreEqual(BuildingBlockGallery.All, block.Gallery);
            Assert.AreEqual(BuildingBlockBehavior.Content, block.Behavior);

            // If we want to use our building block as an AutoText quick part, we need to give it some text and change some properties
            // All the necessary preparation will be done in a custom document visitor that we will accept
            BuildingBlockVisitor visitor = new BuildingBlockVisitor(glossaryDoc);

            block.Accept(visitor);

            // We can find the block we made in the glossary document like this
            BuildingBlock customBlock = glossaryDoc.GetBuildingBlock(BuildingBlockGallery.QuickParts,
                                                                     "My custom building blocks", "Custom Block");

            // Our block contains one section which now contains our text
            Assert.AreEqual("Text inside " + customBlock.Name + '\f',
                            customBlock.FirstSection.Body.FirstParagraph.GetText());
            Assert.AreEqual(customBlock.FirstSection, customBlock.LastSection);

            Assert.AreNotEqual("00000000-0000-0000-0000-000000000000", customBlock.Guid.ToString());
            Assert.AreEqual("My custom building blocks", customBlock.Category);
            Assert.AreEqual(BuildingBlockType.None, customBlock.Type);
            Assert.AreEqual(BuildingBlockGallery.QuickParts, customBlock.Gallery);
            Assert.AreEqual(BuildingBlockBehavior.Paragraph, customBlock.Behavior);

            // Then we can insert it into the document as a new section
            doc.AppendChild(doc.ImportNode(customBlock.FirstSection, true));

            // Or we can find it in Microsoft Word's Building Blocks Organizer and place it manually
            doc.Save(MyDir + @"\Artifacts\BuildingBlocks.BuildingBlock.dotx");
        }
コード例 #7
0
        [Test] //ExSkip
        public void CreateAndInsert()
        {
            // A document's glossary document stores building blocks.
            Document         doc         = new Document();
            GlossaryDocument glossaryDoc = new GlossaryDocument();

            doc.GlossaryDocument = glossaryDoc;

            // Create a building block, name it, and then add it to the glossary document.
            BuildingBlock block = new BuildingBlock(glossaryDoc)
            {
                Name = "Custom Block"
            };

            glossaryDoc.AppendChild(block);

            // All new building block GUIDs have the same zero value by default, and we can give them a new unique value.
            Assert.AreEqual("00000000-0000-0000-0000-000000000000", block.Guid.ToString());

            block.Guid = Guid.NewGuid();

            // The following attributes categorize building blocks
            // in the menu found via Insert -> Quick Parts -> Building Blocks Organizer in Microsoft Word.
            Assert.AreEqual("(Empty Category)", block.Category);
            Assert.AreEqual(BuildingBlockType.None, block.Type);
            Assert.AreEqual(BuildingBlockGallery.All, block.Gallery);
            Assert.AreEqual(BuildingBlockBehavior.Content, block.Behavior);

            // Before we can add this building block to our document, we will need to give it some contents.
            // We will do that and set a category, gallery, and behavior with a document visitor.
            BuildingBlockVisitor visitor = new BuildingBlockVisitor(glossaryDoc);

            block.Accept(visitor);

            // We can access the block that we just made from the glossary document.
            BuildingBlock customBlock = glossaryDoc.GetBuildingBlock(BuildingBlockGallery.QuickParts,
                                                                     "My custom building blocks", "Custom Block");

            // The block itself is a section that contains the text.
            Assert.AreEqual($"Text inside {customBlock.Name}\f", customBlock.FirstSection.Body.FirstParagraph.GetText());
            Assert.AreEqual(customBlock.FirstSection, customBlock.LastSection);
            Assert.DoesNotThrow(() => Guid.Parse(customBlock.Guid.ToString()));     //ExSkip
            Assert.AreEqual("My custom building blocks", customBlock.Category);     //ExSkip
            Assert.AreEqual(BuildingBlockType.None, customBlock.Type);              //ExSkip
            Assert.AreEqual(BuildingBlockGallery.QuickParts, customBlock.Gallery);  //ExSkip
            Assert.AreEqual(BuildingBlockBehavior.Paragraph, customBlock.Behavior); //ExSkip

            // Now, we can insert it into the document as a new section.
            doc.AppendChild(doc.ImportNode(customBlock.FirstSection, true));

            // We can also find it in Microsoft Word's Building Blocks Organizer and place it manually.
            doc.Save(ArtifactsDir + "BuildingBlocks.CreateAndInsert.dotx");
        }
コード例 #8
0
        public void Constructor()
        {
            //ExStart
            //ExFor:DocumentBase
            //ExSummary:Shows how to initialize the subclasses of DocumentBase.
            // DocumentBase is the abstract base class for the Document and GlossaryDocument classes
            Document doc = new Document();

            GlossaryDocument glossaryDoc = new GlossaryDocument();

            doc.GlossaryDocument = glossaryDoc;
            //ExEnd
        }
コード例 #9
0
        [Test] //ExSkip
        public void GlossaryDocument()
        {
            Document doc = new Document();

            GlossaryDocument glossaryDoc = new GlossaryDocument();

            glossaryDoc.AppendChild(new BuildingBlock(glossaryDoc)
            {
                Name = "Block 1"
            });
            glossaryDoc.AppendChild(new BuildingBlock(glossaryDoc)
            {
                Name = "Block 2"
            });
            glossaryDoc.AppendChild(new BuildingBlock(glossaryDoc)
            {
                Name = "Block 3"
            });
            glossaryDoc.AppendChild(new BuildingBlock(glossaryDoc)
            {
                Name = "Block 4"
            });
            glossaryDoc.AppendChild(new BuildingBlock(glossaryDoc)
            {
                Name = "Block 5"
            });

            Assert.AreEqual(5, glossaryDoc.BuildingBlocks.Count);

            doc.GlossaryDocument = glossaryDoc;

            // There is a different ways how to get created building blocks
            Assert.AreEqual("Block 1", glossaryDoc.FirstBuildingBlock.Name);
            Assert.AreEqual("Block 2", glossaryDoc.BuildingBlocks[1].Name);
            Assert.AreEqual("Block 3", glossaryDoc.BuildingBlocks.ToArray()[2].Name);
            Assert.AreEqual("Block 4", glossaryDoc.GetBuildingBlock(BuildingBlockGallery.All, "(Empty Category)", "Block 4").Name);
            Assert.AreEqual("Block 5", glossaryDoc.LastBuildingBlock.Name);

            // We will do that using a custom visitor, which also will give every BuildingBlock in the GlossaryDocument a unique GUID
            GlossaryDocVisitor visitor = new GlossaryDocVisitor();

            glossaryDoc.Accept(visitor);
            Assert.AreEqual(5, visitor.GetDictionary().Count); //ExSkip

            Console.WriteLine(visitor.GetText());

            // We can find our new blocks in Microsoft Word via Insert > Quick Parts > Building Blocks Organizer...
            doc.Save(ArtifactsDir + "BuildingBlocks.GlossaryDocument.dotx");
        }
コード例 #10
0
        public void ClearTextFromStructuredDocumentTags()
        {
            //ExStart
            //ExFor:StructuredDocumentTag.Clear
            //ExSummary:Shows how to delete contents of structured document tag elements.
            Document doc = new Document();

            // Create a plain text structured document tag, and then append it to the document.
            StructuredDocumentTag tag = new StructuredDocumentTag(doc, SdtType.PlainText, MarkupLevel.Block);

            doc.FirstSection.Body.AppendChild(tag);

            // This structured document tag, which is in the form of a text box, already displays placeholder text.
            Assert.AreEqual("Click here to enter text.", tag.GetText().Trim());
            Assert.True(tag.IsShowingPlaceholderText);

            // Create a building block with text contents.
            GlossaryDocument glossaryDoc     = doc.GlossaryDocument;
            BuildingBlock    substituteBlock = new BuildingBlock(glossaryDoc);

            substituteBlock.Name = "My placeholder";
            substituteBlock.AppendChild(new Section(glossaryDoc));
            substituteBlock.FirstSection.EnsureMinimum();
            substituteBlock.FirstSection.Body.FirstParagraph.AppendChild(new Run(glossaryDoc, "Custom placeholder text."));
            glossaryDoc.AppendChild(substituteBlock);

            // Set the structured document tag's "PlaceholderName" property to our building block's name to get
            // the structured document tag to display the contents of the building block in place of the original default text.
            tag.PlaceholderName = "My placeholder";

            Assert.AreEqual("Custom placeholder text.", tag.GetText().Trim());
            Assert.True(tag.IsShowingPlaceholderText);

            // Edit the text of the structured document tag and hide the placeholder text.
            Run run = (Run)tag.GetChild(NodeType.Run, 0, true);

            run.Text = "New text.";
            tag.IsShowingPlaceholderText = false;

            Assert.AreEqual("New text.", tag.GetText().Trim());

            // Use the "Clear" method to clear this structured document tag's contents and display the placeholder again.
            tag.Clear();

            Assert.True(tag.IsShowingPlaceholderText);
            Assert.AreEqual("Custom placeholder text.", tag.GetText().Trim());
            //ExEnd
        }
コード例 #11
0
        public void Constructor()
        {
            //ExStart
            //ExFor:DocumentBase
            //ExSummary:Shows how to initialize the subclasses of DocumentBase.
            Document doc = new Document();

            Assert.AreEqual(typeof(DocumentBase), doc.GetType().BaseType);

            GlossaryDocument glossaryDoc = new GlossaryDocument();

            doc.GlossaryDocument = glossaryDoc;

            Assert.AreEqual(typeof(DocumentBase), glossaryDoc.GetType().BaseType);
            //ExEnd
        }
コード例 #12
0
        public void ClearTextFromStructuredDocumentTags()
        {
            //ExStart
            //ExFor:StructuredDocumentTag.Clear
            //ExSummary:Shows how to delete content of StructuredDocumentTag elements.
            Document doc = new Document();

            // Create a plain text structured document tag and append it to the document
            StructuredDocumentTag tag = new StructuredDocumentTag(doc, SdtType.PlainText, MarkupLevel.Block);

            doc.FirstSection.Body.AppendChild(tag);

            // This structured document tag, which is in the form of a text box, already displays placeholder text
            Assert.AreEqual("Click here to enter text.", tag.GetText().Trim());
            Assert.True(tag.IsShowingPlaceholderText);

            // Create a building block that
            GlossaryDocument glossaryDoc     = doc.GlossaryDocument;
            BuildingBlock    substituteBlock = new BuildingBlock(glossaryDoc);

            substituteBlock.Name = "My placeholder";
            substituteBlock.AppendChild(new Section(glossaryDoc));
            substituteBlock.FirstSection.EnsureMinimum();
            substituteBlock.FirstSection.Body.FirstParagraph.AppendChild(new Run(glossaryDoc, "Custom placeholder text."));
            glossaryDoc.AppendChild(substituteBlock);

            // Set the tag's placeholder to the building block
            tag.PlaceholderName = "My placeholder";

            Assert.AreEqual("Custom placeholder text.", tag.GetText().Trim());
            Assert.True(tag.IsShowingPlaceholderText);

            // Edit the text of the structured document tag and disable showing of placeholder text
            Run run = (Run)tag.GetChild(NodeType.Run, 0, true);

            run.Text = "New text.";
            tag.IsShowingPlaceholderText = false;

            Assert.AreEqual("New text.", tag.GetText().Trim());

            tag.Clear();

            // Clearing a PlainText tag reverts these changes
            Assert.True(tag.IsShowingPlaceholderText);
            Assert.AreEqual("Custom placeholder text.", tag.GetText().Trim());
            //ExEnd
        }
コード例 #13
0
 public void BuildDocument(string[] AutoTextName)
 {
     /* Here's where I look in the Glossary Document Part to determine it there IS AutoText
      * If there isn't, then there's no use in creating the List of AutoText objects!
      */
     gdp = sslmdp.GlossaryDocumentPart;
     if (gdp != null)
     {
         gd = gdp.GlossaryDocument;
         foreach (string atxname in AutoTextName)
         {
             atx = new CBAutoText(atxname, gd.DocParts, ssldoc.Body);
             atx.Insert();
         }
         wrddoc.SaveAs(DOC_PATH_NAME);
         wrddoc.Close();
     }
 }
コード例 #14
0
        public void InvestigateTemplate()
        {
            // I'll use this to understand code and the template package
            using (WordprocessingDocument wrdTemplate = WordprocessingDocument.Open(pathtemplatedoc + TEMPLATE_NAME, false))
            {
                int PartCount = 0;
                // Let's take a look at the Word package parts
                PartCount = wrdTemplate.Parts.Count();
                Console.WriteLine("Looking at the WordprocessingDocument");
                Console.WriteLine("Count of WordprocessingDocument Parts ==> {0}", PartCount);
                Console.WriteLine();
                if (PartCount > 0)
                {
                    Console.WriteLine("Rel ID\tUri\t\t\t\tOpenXml Part Name");
                    foreach (IdPartPair part in wrdTemplate.Parts)
                    {
                        Console.WriteLine("{0}\t{2}\t\t{1}", part.RelationshipId, part.OpenXmlPart.GetType().Name, part.OpenXmlPart.Uri);
                    }
                }
                Console.WriteLine();

                // Let's take a look at the 2nd level: The Main Document Parts
                PartCount = wrdTemplate.MainDocumentPart.Parts.Count();
                Console.WriteLine("Count of Main Document Parts ==> {0}", PartCount);
                Console.WriteLine();
                if (PartCount > 0)
                {
                    Console.WriteLine("Rel ID\tUri\t\t\t\tOpenXml Part Name");
                    foreach (IdPartPair part in wrdTemplate.MainDocumentPart.Parts)
                    {
                        Console.WriteLine("{0}\t{2}\t\t{1}", part.RelationshipId, part.OpenXmlPart.GetType().Name, part.OpenXmlPart.Uri);
                    }
                }
                Console.WriteLine();

                //Now let's take a look at any Glossary Document Part (AutoText Entries) we may find
                GlossaryDocumentPart gDocPart = wrdTemplate.MainDocumentPart.GetPartsOfType <GlossaryDocumentPart>().FirstOrDefault();
                if (gDocPart != null)
                {
                    PartCount = gDocPart.Parts.Count();
                    Console.WriteLine("Count of Glossary Parts ==> {0}", PartCount);
                    Console.WriteLine();
                    if (PartCount > 0)
                    {
                        Console.WriteLine("Rel ID\tUri\t\t\t\t\tOpenXml Part Name");
                        foreach (IdPartPair part in gDocPart.Parts)
                        {
                            Console.WriteLine("{0}\t{2}\t\t{1}", part.RelationshipId, part.OpenXmlPart.GetType().Name, part.OpenXmlPart.Uri);
                        }
                    }
                    Console.WriteLine();
                    GlossaryDocument gDoc = gDocPart.GlossaryDocument;
                    if (gDoc != null)
                    {
                        Console.WriteLine("AutoText Entries!");
                        foreach (DocPart entry in gDoc.DocParts)
                        {
                            if (entry.DocPartProperties.Category.Gallery.Val == DocPartGalleryValues.AutoText)
                            {
                                Console.WriteLine("Entry Name ==> {0}", entry.DocPartProperties.DocPartName.Val);
                            }
                        }
                    }
                }
                else
                {
                    Console.WriteLine("No Glossary Document Part (AutoText Entries) found.");
                }
            }
        }
コード例 #15
0
 public BuildingBlockVisitor(GlossaryDocument ownerGlossaryDoc)
 {
     mBuilder     = new StringBuilder();
     mGlossaryDoc = ownerGlossaryDoc;
 }
コード例 #16
0
 public override VisitorAction VisitGlossaryDocumentEnd(GlossaryDocument glossary)
 {
     mBuilder.AppendLine("Reached end of glossary!");
     mBuilder.AppendLine("BuildingBlocks found: " + mBlocksByGuid.Count);
     return(VisitorAction.Continue);
 }
コード例 #17
0
 public override VisitorAction VisitGlossaryDocumentStart(GlossaryDocument glossary)
 {
     mBuilder.AppendLine("Glossary document found!");
     return(VisitorAction.Continue);
 }
        // Generates content of glossaryDocumentPart1.
        private void GenerateGlossaryDocumentPart1Content(GlossaryDocumentPart glossaryDocumentPart1)
        {
            GlossaryDocument glossaryDocument1 = new GlossaryDocument();
            glossaryDocument1.AddNamespaceDeclaration("ve", "http://schemas.openxmlformats.org/markup-compatibility/2006");
            glossaryDocument1.AddNamespaceDeclaration("o", "urn:schemas-microsoft-com:office:office");
            glossaryDocument1.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
            glossaryDocument1.AddNamespaceDeclaration("m", "http://schemas.openxmlformats.org/officeDocument/2006/math");
            glossaryDocument1.AddNamespaceDeclaration("v", "urn:schemas-microsoft-com:vml");
            glossaryDocument1.AddNamespaceDeclaration("wp", "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing");
            glossaryDocument1.AddNamespaceDeclaration("w10", "urn:schemas-microsoft-com:office:word");
            glossaryDocument1.AddNamespaceDeclaration("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main");
            glossaryDocument1.AddNamespaceDeclaration("wne", "http://schemas.microsoft.com/office/word/2006/wordml");

            DocParts docParts1 = new DocParts();

            DocPart docPart1 = new DocPart();

            DocPartProperties docPartProperties1 = new DocPartProperties();
            DocPartName docPartName1 = new DocPartName() { Val = "DefaultPlaceholder_22675703" };

            Category category1 = new Category();
            Name name1 = new Name() { Val = "General" };
            Gallery gallery1 = new Gallery() { Val = DocPartGalleryValues.Placeholder };

            category1.Append(name1);
            category1.Append(gallery1);

            DocPartTypes docPartTypes1 = new DocPartTypes();
            DocPartType docPartType1 = new DocPartType() { Val = DocPartValues.SdtPlaceholder };

            docPartTypes1.Append(docPartType1);

            Behaviors behaviors1 = new Behaviors();
            Behavior behavior1 = new Behavior() { Val = DocPartBehaviorValues.Content };

            behaviors1.Append(behavior1);
            DocPartId docPartId1 = new DocPartId() { Val = "{2B92B0C5-D732-4214-9E3C-19A9672429AB}" };

            docPartProperties1.Append(docPartName1);
            docPartProperties1.Append(category1);
            docPartProperties1.Append(docPartTypes1);
            docPartProperties1.Append(behaviors1);
            docPartProperties1.Append(docPartId1);

            DocPartBody docPartBody1 = new DocPartBody();

            Paragraph paragraph18 = new Paragraph() { RsidParagraphAddition = "00C275C8", RsidRunAdditionDefault = "00BB6D8B" };

            Run run16 = new Run() { RsidRunProperties = "009C61D3" };

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

            runProperties1.Append(runStyle1);
            Text text16 = new Text();
            text16.Text = "Click here to enter text.";

            run16.Append(runProperties1);
            run16.Append(text16);

            paragraph18.Append(run16);

            docPartBody1.Append(paragraph18);

            docPart1.Append(docPartProperties1);
            docPart1.Append(docPartBody1);

            docParts1.Append(docPart1);

            glossaryDocument1.Append(docParts1);

            glossaryDocumentPart1.GlossaryDocument = glossaryDocument1;
        }
コード例 #19
0
        // Generates content of glossaryDocumentPart1.
        private void GenerateGlossaryDocumentPart1Content(GlossaryDocumentPart glossaryDocumentPart1)
        {
            GlossaryDocument glossaryDocument1 = new GlossaryDocument(){ MCAttributes = new MarkupCompatibilityAttributes(){ Ignorable = "w14 w15 wp14" }  };
            glossaryDocument1.AddNamespaceDeclaration("wpc", "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas");
            glossaryDocument1.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006");
            glossaryDocument1.AddNamespaceDeclaration("o", "urn:schemas-microsoft-com:office:office");
            glossaryDocument1.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
            glossaryDocument1.AddNamespaceDeclaration("m", "http://schemas.openxmlformats.org/officeDocument/2006/math");
            glossaryDocument1.AddNamespaceDeclaration("v", "urn:schemas-microsoft-com:vml");
            glossaryDocument1.AddNamespaceDeclaration("wp14", "http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing");
            glossaryDocument1.AddNamespaceDeclaration("wp", "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing");
            glossaryDocument1.AddNamespaceDeclaration("w10", "urn:schemas-microsoft-com:office:word");
            glossaryDocument1.AddNamespaceDeclaration("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main");
            glossaryDocument1.AddNamespaceDeclaration("w14", "http://schemas.microsoft.com/office/word/2010/wordml");
            glossaryDocument1.AddNamespaceDeclaration("w15", "http://schemas.microsoft.com/office/word/2010/11/wordml");
            glossaryDocument1.AddNamespaceDeclaration("wpg", "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup");
            glossaryDocument1.AddNamespaceDeclaration("wpi", "http://schemas.microsoft.com/office/word/2010/wordprocessingInk");
            glossaryDocument1.AddNamespaceDeclaration("wne", "http://schemas.microsoft.com/office/word/2006/wordml");
            glossaryDocument1.AddNamespaceDeclaration("wps", "http://schemas.microsoft.com/office/word/2010/wordprocessingShape");

            DocParts docParts1 = new DocParts();

            DocPart docPart1 = new DocPart();

            DocPartProperties docPartProperties1 = new DocPartProperties();
            DocPartName docPartName1 = new DocPartName(){ Val = "DefaultPlaceholder_1081868558" };

            Category category1 = new Category();
            Name name1 = new Name(){ Val = "General" };
            Gallery gallery1 = new Gallery(){ Val = DocPartGalleryValues.Placeholder };

            category1.Append(name1);
            category1.Append(gallery1);

            DocPartTypes docPartTypes1 = new DocPartTypes();
            DocPartType docPartType1 = new DocPartType(){ Val = DocPartValues.SdtPlaceholder };

            docPartTypes1.Append(docPartType1);

            Behaviors behaviors1 = new Behaviors();
            Behavior behavior1 = new Behavior(){ Val = DocPartBehaviorValues.Content };

            behaviors1.Append(behavior1);
            DocPartId docPartId1 = new DocPartId(){ Val = "{F039DA22-FC7F-4FBD-92C2-651CCBF1B274}" };

            docPartProperties1.Append(docPartName1);
            docPartProperties1.Append(category1);
            docPartProperties1.Append(docPartTypes1);
            docPartProperties1.Append(behaviors1);
            docPartProperties1.Append(docPartId1);

            DocPartBody docPartBody1 = new DocPartBody();

            Paragraph paragraph19 = new Paragraph(){ RsidParagraphAddition = "00930812", RsidRunAdditionDefault = "00B75576" };

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

            RunProperties runProperties43 = new RunProperties();
            RunStyle runStyle3 = new RunStyle(){ Val = "PlaceholderText" };

            runProperties43.Append(runStyle3);
            Text text25 = new Text();
            text25.Text = "Click here to enter text.";

            run25.Append(runProperties43);
            run25.Append(text25);

            paragraph19.Append(run25);

            docPartBody1.Append(paragraph19);

            docPart1.Append(docPartProperties1);
            docPart1.Append(docPartBody1);

            DocPart docPart2 = new DocPart();

            DocPartProperties docPartProperties2 = new DocPartProperties();
            DocPartName docPartName2 = new DocPartName(){ Val = "DefaultPlaceholder_1081868562" };

            Category category2 = new Category();
            Name name2 = new Name(){ Val = "General" };
            Gallery gallery2 = new Gallery(){ Val = DocPartGalleryValues.Placeholder };

            category2.Append(name2);
            category2.Append(gallery2);

            DocPartTypes docPartTypes2 = new DocPartTypes();
            DocPartType docPartType2 = new DocPartType(){ Val = DocPartValues.SdtPlaceholder };

            docPartTypes2.Append(docPartType2);

            Behaviors behaviors2 = new Behaviors();
            Behavior behavior2 = new Behavior(){ Val = DocPartBehaviorValues.Content };

            behaviors2.Append(behavior2);
            DocPartId docPartId2 = new DocPartId(){ Val = "{00F3F2EC-0290-443B-9815-66648EE1ADF9}" };

            docPartProperties2.Append(docPartName2);
            docPartProperties2.Append(category2);
            docPartProperties2.Append(docPartTypes2);
            docPartProperties2.Append(behaviors2);
            docPartProperties2.Append(docPartId2);

            DocPartBody docPartBody2 = new DocPartBody();

            Paragraph paragraph20 = new Paragraph(){ RsidParagraphAddition = "00930812", RsidRunAdditionDefault = "00B75576" };

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

            RunProperties runProperties44 = new RunProperties();
            RunStyle runStyle4 = new RunStyle(){ Val = "PlaceholderText" };

            runProperties44.Append(runStyle4);
            Text text26 = new Text();
            text26.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.";

            run26.Append(runProperties44);
            run26.Append(text26);

            paragraph20.Append(run26);

            docPartBody2.Append(paragraph20);

            docPart2.Append(docPartProperties2);
            docPart2.Append(docPartBody2);

            DocPart docPart3 = new DocPart();

            DocPartProperties docPartProperties3 = new DocPartProperties();
            DocPartName docPartName3 = new DocPartName(){ Val = "B207B2DF6D0E4E13956E6616811860CA" };

            Category category3 = new Category();
            Name name3 = new Name(){ Val = "General" };
            Gallery gallery3 = new Gallery(){ Val = DocPartGalleryValues.Placeholder };

            category3.Append(name3);
            category3.Append(gallery3);

            DocPartTypes docPartTypes3 = new DocPartTypes();
            DocPartType docPartType3 = new DocPartType(){ Val = DocPartValues.SdtPlaceholder };

            docPartTypes3.Append(docPartType3);

            Behaviors behaviors3 = new Behaviors();
            Behavior behavior3 = new Behavior(){ Val = DocPartBehaviorValues.Content };

            behaviors3.Append(behavior3);
            DocPartId docPartId3 = new DocPartId(){ Val = "{1631777A-52D9-4CE4-A42F-C87B6FA35F21}" };

            docPartProperties3.Append(docPartName3);
            docPartProperties3.Append(category3);
            docPartProperties3.Append(docPartTypes3);
            docPartProperties3.Append(behaviors3);
            docPartProperties3.Append(docPartId3);

            DocPartBody docPartBody3 = new DocPartBody();

            Paragraph paragraph21 = new Paragraph(){ RsidParagraphAddition = "00EF189C", RsidParagraphProperties = "00930812", RsidRunAdditionDefault = "00930812" };

            ParagraphProperties paragraphProperties1 = new ParagraphProperties();
            ParagraphStyleId paragraphStyleId1 = new ParagraphStyleId(){ Val = "B207B2DF6D0E4E13956E6616811860CA" };

            paragraphProperties1.Append(paragraphStyleId1);

            Run run27 = new Run(){ RsidRunProperties = "00D27A45" };

            RunProperties runProperties45 = new RunProperties();
            RunStyle runStyle5 = new RunStyle(){ Val = "PlaceholderText" };

            runProperties45.Append(runStyle5);
            Text text27 = new Text();
            text27.Text = "Click here to enter text.";

            run27.Append(runProperties45);
            run27.Append(text27);

            paragraph21.Append(paragraphProperties1);
            paragraph21.Append(run27);

            docPartBody3.Append(paragraph21);

            docPart3.Append(docPartProperties3);
            docPart3.Append(docPartBody3);

            DocPart docPart4 = new DocPart();

            DocPartProperties docPartProperties4 = new DocPartProperties();
            DocPartName docPartName4 = new DocPartName(){ Val = "4B632797D8B1461898B8F461443A20E0" };

            Category category4 = new Category();
            Name name4 = new Name(){ Val = "General" };
            Gallery gallery4 = new Gallery(){ Val = DocPartGalleryValues.Placeholder };

            category4.Append(name4);
            category4.Append(gallery4);

            DocPartTypes docPartTypes4 = new DocPartTypes();
            DocPartType docPartType4 = new DocPartType(){ Val = DocPartValues.SdtPlaceholder };

            docPartTypes4.Append(docPartType4);

            Behaviors behaviors4 = new Behaviors();
            Behavior behavior4 = new Behavior(){ Val = DocPartBehaviorValues.Content };

            behaviors4.Append(behavior4);
            DocPartId docPartId4 = new DocPartId(){ Val = "{4829C634-4047-4182-9E1A-7F28677ACBC2}" };

            docPartProperties4.Append(docPartName4);
            docPartProperties4.Append(category4);
            docPartProperties4.Append(docPartTypes4);
            docPartProperties4.Append(behaviors4);
            docPartProperties4.Append(docPartId4);

            DocPartBody docPartBody4 = new DocPartBody();

            Paragraph paragraph22 = new Paragraph(){ RsidParagraphAddition = "00EF189C", RsidParagraphProperties = "00930812", RsidRunAdditionDefault = "00930812" };

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

            paragraphProperties2.Append(paragraphStyleId2);

            Run run28 = new Run(){ RsidRunProperties = "00D27A45" };

            RunProperties runProperties46 = new RunProperties();
            RunStyle runStyle6 = new RunStyle(){ Val = "PlaceholderText" };

            runProperties46.Append(runStyle6);
            Text text28 = new Text();
            text28.Text = "Click here to enter text.";

            run28.Append(runProperties46);
            run28.Append(text28);

            paragraph22.Append(paragraphProperties2);
            paragraph22.Append(run28);

            docPartBody4.Append(paragraph22);

            docPart4.Append(docPartProperties4);
            docPart4.Append(docPartBody4);

            docParts1.Append(docPart1);
            docParts1.Append(docPart2);
            docParts1.Append(docPart3);
            docParts1.Append(docPart4);

            glossaryDocument1.Append(docParts1);

            glossaryDocumentPart1.GlossaryDocument = glossaryDocument1;
        }
コード例 #20
0
 public override VisitorAction VisitGlossaryDocumentStart(GlossaryDocument glossary)
 {
     mBuilder.Append("Glossary processing started...\r\n");
     return(VisitorAction.Continue);
 }