[Solved] Create a note

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
briglia23
Posts: 155
Joined: Tue Jun 24, 2008 10:09 am

[Solved] Create a note

Post by briglia23 »

Hi everybody.
I want a macro that insert a note in the selected cell.
The operation is the following one:
I select the cell where I want to insert the note
I press a button that starts the macro for inserts the note in the cell selected before

Thank you
Last edited by Hagar Delest on Wed Jun 25, 2008 5:42 pm, edited 1 time in total.
Reason: tagged the thread as Solved.
OOo 2.3.X on openSuse 10
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: create a note

Post by Villeroy »

Install The Xray Tool. You can not live without it.

Code: Select all

Sub Main
oDoc = thisComponent
oSheet = oDoc.Sheets.getByIndex(0)
oCell = oSheet.getCellByPosition(0, 0)
GlobalScope.BasicLibraries.loadLibrary("XrayTool")
xray oCell
oNote = oCell.getAnnotation() 'or pseudo-property .Annotation
xray oNote
oNote.setString("Hello, Note") 'or pseudo-property .String
End Sub
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
briglia23
Posts: 155
Joined: Tue Jun 24, 2008 10:09 am

Re: create a note

Post by briglia23 »

You are amazing!!
But if i don't know where i want insert a note before.
I want select a cell whit mouse and insert a note in this cell i cant use oCell = oSheet.getCellByPosition(0, 0) because i don't know the cell
OOo 2.3.X on openSuse 10
User avatar
Hagar Delest
Moderator
Posts: 32661
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: create a note

Post by Hagar Delest »

LibreOffice 7.6.2.1 on Xubuntu 23.10 and 7.6.4.1 portable on Windows 10
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: create a note

Post by Villeroy »

I want a macro that insert a note in the selected cell.
Follow the link provided by Hagar de l'Est. A selection in Calc is always one of:
1. a multiple selection of ranges by service "com.sun.star.sheet.SheetCellRanges"
2. some shape (annotation, chart, drawing, ...)
3a. a single range of service "com.sun.star.sheet.SheetCellRange"
3b. which is a single cell if it additionally supports "com.sun.star.sheet.SheetCell" (highlighted or not)
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
briglia23
Posts: 155
Joined: Tue Jun 24, 2008 10:09 am

Re: create a note

Post by briglia23 »

i got it.
i used getCurrentSelection()
OOo 2.3.X on openSuse 10
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: create a note

Post by Villeroy »

briglia23 wrote:i got it.
i used getCurrentSelection()
which might be exactly what you do *not* really want, unless the current selection happens to be a single cell. Use function getActiveCell from the other thread, which always returns the current input cell even if a shape is selected.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Post Reply