VSTO Smart Tag Terms


VSTO smart tags let you easily create a smart tag by adding some terms to it.  For example, consider this simple smart tag in a VSTO worksheet project item.  It creates a smart tag that recognizes the term “Halibut”.  One caveat about using the terms collection–VSTO uses Office’s tokenizer to get words to match against terms.  The tokenizer breaks down text in the document into words.  See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/stagsdk/html/stconWhatsNew_HV01083276.asp for more information–look for “Tokenizer Feature Built Into Smart Tag Infrastructure”.  This means you can’t match a term like “Eric Carter” because the tokenizer will actually convert this into the tokens “Eric” and “Carter” and never give VSTO a token like “Eric Carter”.  If you need to match a term that includes spaces and punctuation, use VSTO smart tag’s support for regular expressions.


using System;


using System.Data;


using System.Drawing;


using System.Windows.Forms;


using Microsoft.VisualStudio.Tools.Applications.Runtime;


using Excel = Microsoft.Office.Interop.Excel;


using Office = Microsoft.Office.Core;


using Microsoft.Office.Tools.Excel;


 


namespace ExcelWorkbook5


{


    public partial class Sheet1


    {


        Action myAction;


 


        private void Sheet1_Startup(object sender, System.EventArgs e)


        {


            SmartTag mySmartTag = new SmartTag(“http://smarttags.vsto.com#fish”, “Fish Tag”);


            mySmartTag.Terms.Add(“Halibut”);


            myAction = new Action(“Show fishey picture…”);


            mySmartTag.Actions = new Action[] { myAction };


            myAction.Click += new ActionClickEventHandler(myAction_Click);


            Globals.ThisWorkbook.VstoSmartTags.Add(mySmartTag);


        }


 


        void myAction_Click(object sender, ActionEventArgs e)


        {


            MessageBox.Show(“Show a fishey picture”);


        }


 


        #region VSTO Designer generated code


        private void InternalStartup()


        {


            this.Startup += new System.EventHandler(Sheet1_Startup);


        }


        #endregion


    }


}


Comments (1)

  1. I want to appologize for the delay in posting Blogs, but we have been very busy on getting Whidbey out…