f you developed smart tags in Office XP, you’ll be interested in the changes in Office 2003. Smart tag technology links text to resources that provide relevant information useful in creating a document. Or even better, relevant information can be inserted right into the document itself. Smart tags in Microsoft Office 2003 have been improved to make them even easier to develop, and they conquer a few limitations.
Smart tags were introduced in Microsoft Office XP, providing a new way to make more meaningful data in documents. A major change in Office 2003, the number of applications supporting smart tags has increased. In Office XP, smart tags were supported in Word, Excel, Outlook (with Word as the e-mail editor), and Internet Explorer, to a limited extent. In Office 2003, all these applications are supported and both PowerPoint 2003 and Access 2003 have been added.
New features have been added to the Microsoft Office Smart Tag Lists (MOSTL). MOSTL provides the capability to define smart tag recognizers in XML. Although it’s not as flexible as implementing smart tags in a programming language, it’s great when you have an easily defined list of words or phrases to be recognized. You can use regular expressions to define search patterns for your recognizer and you’ll see a few examples using MOSTL and regular expressions later in this article.
In addition, the API library has been extended, supporting several new interfaces and enabling new functionality. The Microsoft Smart Tags 2.0 Type Library is backward compatible with the 1.0 version, allowing you to develop smart tags that work in both Office XP and Office 2003. This type library and an example of implementing a smart tag in .NET are discussed in more detail later in this article.
An Introduction to Smart Tags
Smart Tags identify words or phrases within a document, and several are provided with Microsoft Office. For a list of existing smart tags, and to enable and disable smart tags, go to Tools (from within any of the applicable Office 2003 applications) and then choose Auto Correct Options. Click on the Smart Tags tab and you’ll see a list of available smart tags.
Figure 1: The smart tag shows the financial symbol and its smart tag drop-down menu. |
To experiment, enable the Financial Symbols smart tag. Then enter a stock symbol, such as MSFT, in a Word 2003 document. When the symbol is recognized, smart tags make a red-dotted underline under it. When you hover your mouse pointer over it, you’ll see an information icon. Clicking on the icon displays a drop-down menu, as shown in Figure 1. The menu shows a list of actions relevant to the financial symbol.
Another smart tag might look up contact information in your Outlook 2003 contact list. Figure 2 shows the drop-down menu and the actions available with that smart tag.
Although these are good examples of smart tags in action, the number of provided smart tags is limited. It is possible to create your own smart tags using MOSTL or by developing them in a programming language. Then the possibilities of what you can do with smart tags are virtually endless!
MOSTL and Regular Expressions Regular expressions are a powerful form of wildcard searches. Most developers (and even power users) are familiar with regular expressions used to search for files, such as *.doc. When it comes to regular expression pattern matching, you will need more sophisticated patterns. The following pattern matches US phone numbers within a text string.
If you are not familiar with regular expressions, you might find this but of code a little difficult to read. Let’s take a brief look at the syntax of regular expressions. Table 1 lists the most common meta-characters that are used in regular expression patterns. Table 1: This Smart Tag Meta-character listing will make iteasy to follow the exploration.
Examine this by breaking down the phone number pattern shown above. Start at the end of the pattern:
This means that the expression must contain exactly three digits, followed by a hyphen, and then exactly four digits. Thus, 555-1234 is a match. Now look at the first part:
Notice that there is a pipe (|) in the middle, indicating an or operator. On the right side of that you can see:
This will match exactly three digits followed by a hyphen. On the left side of the or (|) you see:
Notice that ( and ) are used to indicate that parenthesis are part of the pattern. In between these is the d{3} indicating exactly three digits. So the pattern matches phone numbers in these formats:
This portion of the pattern ends with a question mark, indicating that the pattern immediately prior to the question mark is optional. Because the area code pattern is grouped in parentheses and the question mark is outside the parentheses, the entire pattern inside the parentheses is optional. The pattern will also be a match:
You could get even more sophisticated and match 281.866.7444 in addition to allowing a space between the various parts of the phone number and match foreign phone numbers. Here’s another example. Let’s say you use a bug-tracking Web site to track issues that need to be addressed in your current project. You can define a smart tag that recognizes “Bug #123456” or “bug 123456” and link directly to that bug’s details on the Web site. Here is the regular expression that matches these phrases:
You can create a smart tag definition to recognize this pattern and link to the Web site. It looks like Listing 2. Note that the URL in this example is a placeholder that should be replaced with the URL to your bug-tracking Web site. The resulting smart tag menu is shown in Figure 4.
|