Ejemplo n.º 1
0
        public void ClearContentsControl()
        {
            //ExStart:ClearContentsControl
            Document doc = new Document(MyDir + "Structured document tags.docx");

            StructuredDocumentTag sdt = (StructuredDocumentTag)doc.GetChild(NodeType.StructuredDocumentTag, 0, true);

            sdt.Clear();

            doc.Save(ArtifactsDir + "WorkingWithSdt.ClearContentsControl.doc");
            //ExEnd:ClearContentsControl
        }
        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
        }
Ejemplo n.º 3
0
        public static void ClearContentsControl(string dataDir)
        {
            // ExStart:ClearContentsControl

            Document doc = new Document(dataDir + "input.docx");
            StructuredDocumentTag sdt = (StructuredDocumentTag)doc.GetChild(NodeType.StructuredDocumentTag, 0, true);

            sdt.Clear();

            dataDir = dataDir + "ClearContentsControl_out.doc";

            // Save the document to disk.
            doc.Save(dataDir);
            // ExEnd:ClearContentsControl
            Console.WriteLine("\nClear the contents of content control successfully.");
        }
Ejemplo n.º 4
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
        }
Ejemplo n.º 5
0
        public static void Run()
        {
            // ExStart:ClearContentsControl
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_WorkingWithStructuredDocumentTag();

            Document doc = new Document(dataDir + "input.docx");
            StructuredDocumentTag sdt = (StructuredDocumentTag)doc.GetChild(NodeType.StructuredDocumentTag, 0, true);

            sdt.Clear();

            dataDir = dataDir + "ClearContentsControl_out.doc";

            // Save the document to disk.
            doc.Save(dataDir);
            // ExEnd:ClearContentsControl
            Console.WriteLine("\nClear the contents of content control successfully.");
        }