SmartTagRecognizeContext.PersistTag 方法

存放關於智慧標籤的資訊。這個型別或成員僅適用於 2007 Microsoft Office system 專案。智慧標籤在 Office 2010 中已被取代。
.

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

語法

'宣告
Sub PersistTag ( _
    propertyBag As ISmartTagProperties _
)
void PersistTag(
    ISmartTagProperties propertyBag
)

參數

  • propertyBag
    型別:Microsoft.Office.Interop.SmartTag.ISmartTagProperties
    內含語彙基元 (Token) 索引鍵值組的屬性包。可以是 nullnull 參考 (即 Visual Basic 中的 Nothing)。

例外狀況

例外狀況 條件
InvalidOperationException

PersistTag 不是從 Recognize 方法呼叫的。

備註

Recognize 方法的實作呼叫 PersistTag,表示在文字中找到智慧標籤。使用 propertyBag 參數認可智慧標籤的任何自訂屬性。您可以使用這些屬性,自訂在選取智慧標籤捷徑功能表項目時所採取的動作。

範例

下列程式碼範例示範如何從 Recognize 方法的實作呼叫 PersistTag。這項實作會將每個智慧標籤詞彙與儲存格內容做比較。程式碼會針對儲存格中的每個智慧標籤詞彙分別加入自訂智慧標籤屬性,然後使用 PersistTag 方法辨認智慧標籤。本範例假設您已從 [加入參考] 對話方塊的 [.NET] 索引標籤,新增 [Microsoft.Office.Interop.SmartTag] 的參考。這個程式碼範例是 ISmartTagExtension 介面完整範例的一部分。

Private Sub Recognize(ByVal text As String, 
    ByVal site As ISmartTagRecognizerSite, ByVal tokenList As ISmartTagTokenList, 
    ByVal context As SmartTagRecognizeContext) Implements ISmartTagExtension.Recognize

    ' Determine whether each smart tag term exists in the document text.
    Dim Term As String
    For Each Term In smartTagDemo.Terms

        ' Search the cell text for the first instance of 
        ' the current smart tag term.
        Dim index As Integer = context.CellText.IndexOf(Term, 0)

        If (index >= 0) Then

            ' Create a smart tag token and a property bag for the 
            ' recognized term.
            Dim propertyBag As ISmartTagProperties = site.GetNewPropertyBag()

            ' Write a new property value.
            Dim key As String = "Key1"
            propertyBag.Write(key, DateTime.Now)

            ' 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. 
            Exit For
        End If
    Next
End Sub
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;
        }
    }
}

.NET Framework 安全性

請參閱

參考

SmartTagRecognizeContext 介面

Microsoft.Office.Tools.Excel 命名空間