[Test] //ExSkip
        public void SmartTags()
        {
            Document doc      = new Document();
            SmartTag smartTag = new SmartTag(doc);

            smartTag.Element = "date";

            // Specify a date and set smart tag properties accordingly
            smartTag.AppendChild(new Run(doc, "May 29, 2019"));

            smartTag.Properties.Add(new CustomXmlProperty("Day", "", "29"));
            smartTag.Properties.Add(new CustomXmlProperty("Month", "", "5"));
            smartTag.Properties.Add(new CustomXmlProperty("Year", "", "2019"));

            // Set the smart tag's uri to the default
            smartTag.Uri = "urn:schemas-microsoft-com:office:smarttags";

            doc.FirstSection.Body.FirstParagraph.AppendChild(smartTag);
            doc.FirstSection.Body.FirstParagraph.AppendChild(new Run(doc, " is a date. "));

            // Create and add one more smart tag, this time for a financial symbol
            smartTag         = new SmartTag(doc);
            smartTag.Element = "stockticker";
            smartTag.Uri     = "urn:schemas-microsoft-com:office:smarttags";

            smartTag.AppendChild(new Run(doc, "MSFT"));

            doc.FirstSection.Body.FirstParagraph.AppendChild(smartTag);
            doc.FirstSection.Body.FirstParagraph.AppendChild(new Run(doc, " is a stock ticker."));

            // Print all the smart tags in our document with a document visitor
            doc.Accept(new SmartTagVisitor());

            doc.Save(ArtifactsDir + "StructuredDocumentTag.SmartTags.docx");
        }
        [Test] //ExSkip
        public void Create()
        {
            Document doc = new Document();

            // A smart tag appears in a document with Microsoft Word recognizes a part of its text as some form of data,
            // such as a name, date, or address, and converts it to a hyperlink that displays a purple dotted underline.
            SmartTag smartTag = new SmartTag(doc);

            // Smart tags are composite nodes that contain their recognized text in its entirety.
            // Add contents to this smart tag manually.
            smartTag.AppendChild(new Run(doc, "May 29, 2019"));

            // Microsoft Word may recognize the above contents as being a date.
            // Smart tags use the "Element" property to reflect the type of data they contain.
            smartTag.Element = "date";

            // Some smart tag types process their contents further into custom XML properties.
            smartTag.Properties.Add(new CustomXmlProperty("Day", string.Empty, "29"));
            smartTag.Properties.Add(new CustomXmlProperty("Month", string.Empty, "5"));
            smartTag.Properties.Add(new CustomXmlProperty("Year", string.Empty, "2019"));

            // Set the smart tag's URI to the default value.
            smartTag.Uri = "urn:schemas-microsoft-com:office:smarttags";

            doc.FirstSection.Body.FirstParagraph.AppendChild(smartTag);
            doc.FirstSection.Body.FirstParagraph.AppendChild(new Run(doc, " is a date. "));

            // Create another smart tag for a stock ticker.
            smartTag         = new SmartTag(doc);
            smartTag.Element = "stockticker";
            smartTag.Uri     = "urn:schemas-microsoft-com:office:smarttags";

            smartTag.AppendChild(new Run(doc, "MSFT"));

            doc.FirstSection.Body.FirstParagraph.AppendChild(smartTag);
            doc.FirstSection.Body.FirstParagraph.AppendChild(new Run(doc, " is a stock ticker."));

            // Print all the smart tags in our document using a document visitor.
            doc.Accept(new SmartTagPrinter());

            // Older versions of Microsoft Word support smart tags.
            doc.Save(ArtifactsDir + "SmartTag.Create.doc");

            // Use the "RemoveSmartTags" method to remove all smart tags from a document.
            Assert.AreEqual(2, doc.GetChildNodes(NodeType.SmartTag, true).Count);

            doc.RemoveSmartTags();

            Assert.AreEqual(0, doc.GetChildNodes(NodeType.SmartTag, true).Count);
            TestCreate(new Document(ArtifactsDir + "SmartTag.Create.doc")); //ExSkip
        }
Example #3
0
        [Test] //ExSkip
        public void Create()
        {
            Document doc      = new Document();
            SmartTag smartTag = new SmartTag(doc);

            smartTag.Element = "date";

            // Specify a date and set smart tag properties accordingly
            smartTag.AppendChild(new Run(doc, "May 29, 2019"));

            smartTag.Properties.Add(new CustomXmlProperty("Day", string.Empty, "29"));
            smartTag.Properties.Add(new CustomXmlProperty("Month", string.Empty, "5"));
            smartTag.Properties.Add(new CustomXmlProperty("Year", string.Empty, "2019"));

            // Set the smart tag's uri to the default
            smartTag.Uri = "urn:schemas-microsoft-com:office:smarttags";

            doc.FirstSection.Body.FirstParagraph.AppendChild(smartTag);
            doc.FirstSection.Body.FirstParagraph.AppendChild(new Run(doc, " is a date. "));

            // Create and add one more smart tag, this time for a financial symbol
            smartTag         = new SmartTag(doc);
            smartTag.Element = "stockticker";
            smartTag.Uri     = "urn:schemas-microsoft-com:office:smarttags";

            smartTag.AppendChild(new Run(doc, "MSFT"));

            doc.FirstSection.Body.FirstParagraph.AppendChild(smartTag);
            doc.FirstSection.Body.FirstParagraph.AppendChild(new Run(doc, " is a stock ticker."));

            // Print all the smart tags in our document with a document visitor
            doc.Accept(new SmartTagVisitor());

            // SmartTags are supported by older versions of microsoft Word
            doc.Save(ArtifactsDir + "SmartTag.Create.doc");

            // We can strip a document of all its smart tags with RemoveSmartTags()
            Assert.AreEqual(2, doc.GetChildNodes(NodeType.SmartTag, true).Count);
            doc.RemoveSmartTags();
            Assert.AreEqual(0, doc.GetChildNodes(NodeType.SmartTag, true).Count);

            TestCreate(new Document(ArtifactsDir + "SmartTag.Create.doc")); //ExSkip
        }
Example #4
0
        public void SmartTagProperty()
        {
            //ExStart
            //ExFor:CustomXmlProperty
            //ExFor:CustomXmlProperty.#ctor(String,String,String)
            //ExFor:CustomXmlProperty.Name
            //ExFor:CustomXmlProperty.Value
            //ExSummary:Shows how to work with smart tag properties.
            Document doc      = new Document();
            SmartTag smartTag = new SmartTag(doc);

            smartTag.Element = "date";

            // Specify a date and set smart tag properties accordingly
            smartTag.AppendChild(new Run(doc, "May 29, 2019"));

            smartTag.Properties.Add(new CustomXmlProperty("Day", "", "29"));
            smartTag.Properties.Add(new CustomXmlProperty("Month", "", "5"));
            smartTag.Properties.Add(new CustomXmlProperty("Year", "", "2019"));

            doc.FirstSection.Body.FirstParagraph.AppendChild(smartTag);
            doc.FirstSection.Body.FirstParagraph.AppendChild(new Run(doc, " is a date."));

            doc.Save(ArtifactsDir + "SmartTagProperties.doc");
            //ExEnd
            doc = new Document(ArtifactsDir + "SmartTagProperties.doc");

            NodeCollection smartTags = doc.GetChildNodes(NodeType.SmartTag, true);

            Assert.AreEqual(1, smartTags.Count);
            smartTag = (SmartTag)smartTags[0];
            Assert.AreEqual(3, smartTag.Properties.Count);
            Assert.AreEqual("29", smartTag.Properties["Day"].Value);
            Assert.AreEqual("5", smartTag.Properties["Month"].Value);
            Assert.AreEqual("2019", smartTag.Properties["Year"].Value);
        }