Udostępnij za pośrednictwem


Metoda SmartTagRecognizeContext.PersistTag —

Przechowuje informacje o tagu inteligentnego.Ten typ lub element członkowski jest przeznaczony do stosowania wyłącznie w projektach dla systemu Microsoft Office 2007. W systemie Office 2010 tagi inteligentne nie są już używane.
.

Przestrzeń nazw:  Microsoft.Office.Tools.Excel
Zestaw:  Microsoft.Office.Tools.Excel (w Microsoft.Office.Tools.Excel.dll)

Składnia

'Deklaracja
Sub PersistTag ( _
    propertyBag As ISmartTagProperties _
)
void PersistTag(
    ISmartTagProperties propertyBag
)

Parametry

  • propertyBag
    Typ: Microsoft.Office.Interop.SmartTag.ISmartTagProperties
    Torbę właściwości zawierające par kluczy i wartości dla tokenu.Can be nullodwołanie o wartości null (Nothing w języku Visual Basic).

Wyjątki

Wyjątek Warunek
InvalidOperationException

PersistTagnie została wywołana z Recognize metody.

Uwagi

Wywołanie PersistTag z implementacją Recognize metodę, aby wskazać, że tag inteligentny został znaleziony w tekście.Użyj propertyBag parametr przekazać żadnych właściwości niestandardowych dla tagu inteligentnego.Aby dostosować Akcja podejmowana, gdy zostanie zaznaczony element z menu skrótów tagów inteligentnych, można użyć tych właściwości.

Przykłady

Poniższy przykład kodu pokazuje sposób wywołania PersistTag z implementacją Recognize metody.Ta implementacja porównuje każdego terminu tag inteligentny do zawartości komórki.Dla każdego warunku tagu inteligentnego w komórce kod dodaje właściwości niestandardowych tagów inteligentnych, a następnie używa PersistTag metody do rozpoznawania tagów inteligentnych.W tym przykładzie założono, że dodano odniesienie do Microsoft.Office.Interop.SmartTag z .NET na karcie Dodaj odwołanie okno dialogowe.Poniższy przykład kodu jest częścią większych przykład, przewidziane ISmartTagExtension interfejsu.

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;
        }
    }
}

Zabezpieczenia programu .NET Framework

Zobacz też

Informacje

SmartTagRecognizeContext Interfejs

Przestrzeń nazw Microsoft.Office.Tools.Excel