Insert a comment with custom presets

From The Document Foundation Wiki
< Macros‎ | Writer
Jump to: navigation, search


Description

Insert a string in the cursor position in a current document.

Basic code

 1 Sub insert_in_cursor_position()
 2     data = "Hello World with Python"
 3 
 4     REM Current document
 5     doc = ThisComponent
 6 
 7     REM Current selection always return a ranges, and get to end
 8     text = doc.CurrentSelection.getByIndex(0).End
 9     
10     REM Write data
11     text.String = data    
12 End Sub

References to API

Line Link
5 com.sun.star.text.TextDocument
8, 11 com.sun.star.text.XTextRange