SmartTag.PersistTag Метод () (2007 System)
Обновлен: Ноябрь 2007
Хранит сведения о смарт-теге.
Пространство имен: Microsoft.Office.Tools.Excel
Сборка: Microsoft.Office.Tools.Excel.v9.0 (в Microsoft.Office.Tools.Excel.v9.0.dll)
Синтаксис
'Декларация
Protected Sub PersistTag ( _
propertyBag As ISmartTagProperties _
)
'Применение
Dim propertyBag As ISmartTagProperties
Me.PersistTag(propertyBag)
protected void PersistTag(
ISmartTagProperties propertyBag
)
Параметры
- propertyBag
Тип: ISmartTagProperties
Пакет свойств, содержащий ключ и пары значений маркера. Может иметь значение nullссылка null (Nothing в Visual Basic).
Исключения
Исключение | Условие |
---|---|
InvalidOperationException | PersistTag не вызывался из Recognize. |
Заметки
PersistTag сохраняет распознаваемый тег. Вызовите его из метода Recognize, чтобы указать, что в тексте обнаружен смарт-тег. Используйте параметр propertyBag для сохранения пользовательских свойств смарт-тега. Можно использовать свойства для настройки действия, если выбран элемент контекстного меню смарт-тега.
Примеры
В следующем примере кода демонстрируется переопределение метода Recognize в классе, производном от класса Microsoft.Office.Tools.Excel.SmartTag. Эта реализация Recognize сравнивает каждый термин смарт-тега с содержимым ячейки. Если в ячейке найден термин смарт-тега, код добавляет пользовательское свойство к смарт-тегу, а затем использует метод PersistTag(ISmartTagProperties) для распознавания смарт-тега. В данном примере предполагается, что была добавлена ссылка на библиотеку типов Microsoft Smart Tags 2.0 на вкладке COM диалогового окна Добавление ссылки. Данный пример кода является частью большого примера, приведенного в описании класса SmartTag.
Protected Overrides Sub Recognize(ByVal text As String, _
ByVal site As ISmartTagRecognizerSite, _
ByVal tokenList As ISmartTagTokenList)
' Determine whether each smart tag term exists in
' the document text.
Dim Term As String
For Each Term In Me.Terms
' Search the cell text for the first instance of
' the current smart tag term.
Dim index As Integer = Me.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
Me.PersistTag(propertyBag)
' This implementation only finds the first instance
' of a smart tag term in the cell.
Exit For
End If
Next
End Sub
protected override void Recognize(string text,
ISmartTagRecognizerSite site, ISmartTagTokenList tokenList)
{
// Determine whether each smart tag term exists in
// the document text.
foreach (string term in this.Terms)
{
// Search the cell text for the first instance of
// the current smart tag term.
int index = this.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
this.PersistTag(propertyBag);
// This implementation only finds the first instance
// of a smart tag term in the cell.
break;
}
}
}
Разрешения
- Полное доверие для непосредственно вызывающего метода. Этот член не может быть использован частично доверенным кодом. Дополнительные сведения см. в разделе Использование библиотек из не вполне надежного кода.