Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

ISmartTagExtension Interface

Represents an extension of a smart tag in an Excel worksheet that is customized by using Office development tools in Visual Studio. The extension defines a custom recognizer for the smart tag.

Namespace:  Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel (in Microsoft.Office.Tools.Excel.dll)

[GuidAttribute("baa275c5-e25c-49ba-87be-dbe0712f7eb1")]
public interface ISmartTagExtension : IExtension

The ISmartTagExtension type exposes the following members.

  NameDescription
Public propertyExtensionBaseGets the object that is being extended by this IExtension. (Inherited from IExtension.)
Top

  NameDescription
Public methodRecognizeSearches text in the cell for recognized terms. This type or member is intended to be used only in projects for the 2007 Microsoft Office system. Smart tags are deprecated in Office 2010.
.
Top

Implement the ISmartTagExtension interface if you want to control how Excel recognizes smart tags in worksheets.

Usage

This type is intended to be used only in projects for Excel 2007. Smart tags are deprecated in Excel 2010.

The following code example demonstrates how to implement ISmartTagExtension to create your own smart tag recognizer. The example implements the Recognize method to recognize each smart tag term found in a cell. This example assumes that you have added a reference to Microsoft.Office.Interop.SmartTag from the .NET tab of the Add Reference dialog box.

using System;
using System.Windows.Forms;
using Microsoft.Office.Interop.SmartTag;
using Microsoft.Office.Tools.Excel;

namespace Trin_ExcelDerivedSmartTags4
{
    class CustomSmartTag : ISmartTagExtension
    {
        // Declare the smart tag.
        Microsoft.Office.Tools.Excel.SmartTag smartTagDemo;

        // Declare actions for this smart tag. 
        private Microsoft.Office.Tools.Excel.Action Action1;
        private Microsoft.Office.Tools.Excel.Action Action2;

        public CustomSmartTag()
        {
            this.smartTagDemo = Globals.Factory.CreateSmartTag(
                "http://www.contoso.com/Demo#DemoSmartTag", "Custom Smart Tag", this);

            Action1 = Globals.Factory.CreateAction("Display property value");
            Action2 = Globals.Factory.CreateAction("Display smart tag details");

            smartTagDemo.Terms.AddRange(new string[] { "sales", "organization" });
            smartTagDemo.Actions = new Microsoft.Office.Tools.Excel.Action[] { 
                Action1, Action2 };

            Action1.Click += new ActionClickEventHandler(Action1_Click);
            Action2.Click += new ActionClickEventHandler(Action2_Click);
        }

        void ISmartTagExtension.Recognize(string text, ISmartTagRecognizerSite site, 
            ISmartTagTokenList tokenList, SmartTagRecognizeContext context)
        {

            // Determine whether each smart tag term exists in the document text. 
            foreach (string term in smartTagDemo.Terms)
            {
                // Search the cell text for the first instance of the current smart tag term. 
                int index = context.CellText.IndexOf(term, 0);

                if (index >= 0)
                {
                    // Create a smart tag token and a property bag for the recognized term.
                    ISmartTagProperties propertyBag = site.GetNewPropertyBag();

                    // Write a new property value.                  
                    string key = "Key1";
                    propertyBag.Write(key, DateTime.Now.ToString());

                    // Attach the smart tag to the term in the document
                    context.PersistTag(propertyBag);

                    // This implementation only finds the first instance of a  
                    // smart tag term in the cell.  
                    break;
                }
            }
        }

        // This action displays the property value for the term. 
        private void Action1_Click(object sender,
            Microsoft.Office.Tools.Excel.ActionEventArgs e)
        {
            ISmartTagProperties propertyBag = e.Properties;
            string key = "Key1";
            MessageBox.Show("The corresponding value of " + key +
                " is: " + propertyBag.get_Read(key));
        }

        // This action displays smart tag details. 
        private void Action2_Click(object sender,
            Microsoft.Office.Tools.Excel.ActionEventArgs e)
        {
            MessageBox.Show("The current smart tag caption is '" +
                smartTagDemo.Caption + "'. The current smart tag type is '" +
                smartTagDemo.SmartTagType + "'.");
        }

        public Microsoft.Office.Tools.Excel.SmartTag Base
        {
            get { return smartTagDemo; }
        }

        public object ExtensionBase
        {
            get { return smartTagDemo; }
        }
    }
Show:
© 2014 Microsoft