SmartTagCollection 介面

表示使用 Visual Studio 的 Office 開發工具建立之 Word 或 Excel 方案中的智慧標籤集合。

命名空間:  Microsoft.Office.Tools
組件:  Microsoft.Office.Tools.Common (在 Microsoft.Office.Tools.Common.dll 中)

語法

'宣告
<GuidAttribute("30a90086-8c89-4e19-8299-47765d808408")> _
Public Interface SmartTagCollection _
    Inherits IEnumerable, IDisposable
[GuidAttribute("30a90086-8c89-4e19-8299-47765d808408")]
public interface SmartTagCollection : IEnumerable, 
    IDisposable

SmartTagCollection 型別會公開下列成員。

屬性

  名稱 說明
公用屬性 Item 取得位於指定索引上的智慧標籤。

回頁首

方法

  名稱 說明
公用方法 Add 將智慧標籤加入至 SmartTagCollection 的結尾。
公用方法 AddRange 將智慧標籤陣列加入至 SmartTagCollection 的結尾。
公用方法 BeginInit 基礎架構。
公用方法 Contains 判斷 SmartTagCollection 是否包含特定的智慧標籤。
公用方法 CopyTo 將 SmartTagCollection 中的智慧標籤複製到一維智慧標籤陣列,從指定的索引開始複製。
公用方法 Dispose 執行與釋放 (Free)、釋放 (Release) 或重設 Unmanaged 資源相關聯之應用程式定義的工作。 (繼承自 IDisposable)。
公用方法 EndInit 基礎架構。
公用方法 GetEnumerator 傳回會逐一查看集合的列舉程式。 (繼承自 IEnumerable)。
公用方法 IndexOf 判斷所指定之智慧標籤在這個 SmartTagCollection 中的索引。
公用方法 Insert 將智慧標籤插入至位於指定索引上的 SmartTagCollection。
公用方法 Remove 從 SmartTagCollection 中移除智慧標籤。

回頁首

備註

當您建立智慧標籤時,您會將 SmartTagBase 物件加入至 Workbook.VstoSmartTagsDocument.VstoSmartTags 屬性中。 這些屬性具有 SmartTagCollection 型別。

如需 Office 方案中智慧標籤的詳細資訊,請參閱智慧標籤概觀

注意事項注意事項

此介面是由 Visual Studio Tools for Office Runtime 所實作, 並不能實作於您的程式碼中。 如需詳細資訊,請參閱 Visual Studio Tools for Office Runtime 概觀

使用方式

這個型別僅適用於 Excel 2007 和 Word 2007 專案。 Excel 2010 和 Word 2010 中已取代智慧標籤。 如需詳細資訊,請參閱智慧標籤概觀

本文件說明此型別用於以 .NET Framework 4 為目標之 Office 專案的版本。在以 .NET Framework 3.5 為目標的專案中,此型別可能會有不同的成員,而為此型別提供的程式碼範例可能無法運作。 如需此型別在以 .NET Framework 3.5 為目標之專案中的相關文件,請參閱下列 Visual Studio 2008 文件中的參考章節:https://go.microsoft.com/fwlink/?LinkId=160658 (英文)。

範例

下列程式碼會使用 Add 方法,將 Microsoft.Office.Tools.Excel.SmartTag 加入至 Workbook.VstoSmartTags 屬性所公開 (Expose) 之智慧標籤的集合。 這個程式碼範例是 Microsoft.Office.Tools.Excel.Action 的完整範例的一部分。

這是示範文件層級自訂的範例。

WithEvents displayAddress As Microsoft.Office.Tools.Excel.Action

Private Sub AddSmartTag()

    ' Create the smart tag for .NET Framework 4 projects.
    Dim smartTagDemo As Microsoft.Office.Tools.Excel.SmartTag = _
        Globals.Factory.CreateSmartTag(
        "www.microsoft.com/Demo#DemoSmartTag",
        "Demonstration Smart Tag")

    ' For .NET Framework 3.5 projects, use the following code to create the smart tag.
    ' Dim smartTagDemo As New  _
    '    Microsoft.Office.Tools.Excel.SmartTag( _
    '    "www.microsoft.com/Demo#DemoSmartTag", _
    '    "Demonstration Smart Tag")

    ' Specify a term and an expression to recognize.
    smartTagDemo.Terms.Add("sale")
    smartTagDemo.Expressions.Add( _
        New System.Text.RegularExpressions.Regex( _
        "[I|i]ssue\s\d{5,6}"))

    ' Create the action for .NET Framework 4 projects.
    displayAddress = Globals.Factory.CreateAction("To be replaced")

    ' For .NET Framework 3.5 projects, use the following code to create the action.
    ' displayAddress = New Microsoft.Office.Tools.Excel.Action("To be replaced")

    ' Add the action to the smart tag.
    smartTagDemo.Actions = New Microsoft.Office.Tools.Excel.Action() { _
            displayAddress}

    ' Add the smart tag.
    Me.VstoSmartTags.Add(smartTagDemo)
End Sub
private Microsoft.Office.Tools.Excel.Action displayAddress;

private void AddSmartTag()
{
    // Create the smart tag for .NET Framework 4 projects.
    Microsoft.Office.Tools.Excel.SmartTag smartTagDemo =
        Globals.Factory.CreateSmartTag(
            "www.microsoft.com/Demo#DemoSmartTag",
            "Demonstration Smart Tag");

    // For .NET Framework 3.5 projects, use the following code to create the smart tag.
    // Microsoft.Office.Tools.Excel.SmartTag smartTagDemo =
        // new Microsoft.Office.Tools.Excel.SmartTag(
        //     "www.microsoft.com/Demo#DemoSmartTag",
        //     "Demonstration Smart Tag");

    // Specify a term and an expression to recognize.
    smartTagDemo.Terms.Add("sale");
    smartTagDemo.Expressions.Add(
        new System.Text.RegularExpressions.Regex(
        @"[I|i]ssue\s\d{5,6}"));

    // Create the action for .NET Framework 4 projects.
    displayAddress = Globals.Factory.CreateAction("To be replaced");

    // For .NET Framework 3.5 projects, use the following code to create the action.
    // displayAddress = new Microsoft.Office.Tools.Excel.Action("To be replaced");

    // Add the action to the smart tag.
    smartTagDemo.Actions = new Microsoft.Office.Tools.Excel.Action[] { 
        displayAddress };

    // Add the smart tag.
    this.VstoSmartTags.Add(smartTagDemo);

    displayAddress.BeforeCaptionShow += new 
        Microsoft.Office.Tools.Excel.BeforeCaptionShowEventHandler(
        DisplayAddress_BeforeCaptionShow);

    displayAddress.Click += new 
        Microsoft.Office.Tools.Excel.ActionClickEventHandler(
        DisplayAddress_Click);
}

請參閱

參考

Microsoft.Office.Tools 命名空間

其他資源

智慧標籤概觀