次の方法で共有


SmartTagRecognizeContext.PersistTag メソッド

スマート タグに関する情報を格納します。

名前空間:  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
    トークンのキーと値の組み合わせを格納しているプロパティ バッグ。nullnull 参照 (Visual Basic では Nothing) の場合があります。

例外

例外 条件
InvalidOperationException

PersistTag が、Recognize メソッドから呼び出されませんでした。

解説

スマート タグがテキスト内で見つかったことを示すには、PersistTag を Recognize メソッドの実装から呼び出します。 スマート タグ用の任意のカスタム プロパティをコミットするには、propertyBag パラメーターを使用します。 これらのプロパティを使用すると、スマート タグのショートカット メニューで項目の 1 つを選択した場合のアクションをカスタマイズできます。

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 名前空間