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.

Python code

 1 def insert_in_cursor_position():
 2     data = 'Hello World with Python'
 3 
 4     # ~ Current document
 5     doc = XSCRIPTCONTEXT.getDocument()
 6 
 7     # ~ Current selection always return a ranges, and get to end
 8     text = doc.CurrentSelection[0].End
 9     
10     # ~ Write data
11     text.String = data
12     
13     return

References to API

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