OO-Snippets: insert remove annotations

Commons

Keywordsannotation, note, text content
LanguageOOBasic
ApplicationWriter
AuthorsPaolo Mantovani (initial)
Supported Versions1.0.x  1.1.x  2.0.x  
Supported OSAll  
QuestionHow to insert and remove annotations in text documents?
Answer

Text annotations are a special type of text fields, therefore, in order to insert and remove annotations you must proceed in the same manner as for other kind of text contents

See the example below:

The first routine shows how to add an annotation

The second shows how to find and remove all annotations in a document

Code-Snippet-Listing (snippet-source)

REM  *****  BASIC  *****

Sub Example_InsertAnnotation
	oDoc = ThisComponent
	oTextCursor = oDoc.Text.createTextCursor
	oTextCursor.goToEnd(False)
	
	Dim oDate As New com.sun.star.util.Date
	With oDate
		.Day = Day(Now)
		.Month = Month(Now)
		.Year = Year(Now)
	End With
	
	oTextAnnotation = oDoc.createInstance("com.sun.star.text.TextField.Annotation")
	With oTextAnnotation
		.Content = "Paolo was here!!"
		.Author = "PM"
		.Date = oDate
	End With
	
	oDoc.Text.insertTextContent( oTextCursor, oTextAnnotation, True) 	

End Sub


Sub Example_RemoveAllAnnotations
	oDoc = ThisComponent	
	oEnum = oDoc.TextFields.createEnumeration
	
	Do While oEnum.hasMoreElements
		oTField = oEnum.nextElement
		If oTField.supportsService("com.sun.star.text.TextField.Annotation") Then
			MsgBox oTField.Content, 16,"Annotation detected!!"
			oDoc.Text.removeTextContent(oTField)
			MsgBox "Annotation Removed!!"
		End If
	Loop

End Sub

Changelog

DateUserModification
2005-05-31paolomantovaniInitial version

and