[Solved] Calc - Insert Comment to Cell

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
ikw_chen
Posts: 17
Joined: Tue Apr 12, 2011 4:03 pm

[Solved] Calc - Insert Comment to Cell

Post by ikw_chen »

Hi All,

I would like to insert comment into calc's cell, but on the xCell interface only have two method setValue and setFormula.

Code: Select all

XSpreadsheet xSheet = (XSpreadsheet)UnoRuntime.queryInterface(XSpreadsheet.class, oSheet);

xCell = nameRange.getCellByPosition(0, 1);

xCell.setValue
xCell.setFormula
Thanks for advices!
Last edited by ikw_chen on Mon Jun 06, 2011 6:24 pm, edited 1 time in total.
Openoffice 3.3 on WinXP
User avatar
Zizi64
Volunteer
Posts: 11363
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Calc - Insert Comment to Cell

Post by Zizi64 »

Hi,

I found some examples:
http://www.oooforum.org/forum/viewtopic.phtml?t=32826
but do not work for me in my LibreOffice3.3.2....
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
FJCC
Moderator
Posts: 9280
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Calc - Insert Comment to Cell

Post by FJCC »

I found this approach in the Developer's Guide and it works for me. The Annotations are handled as a collection at the sheet level, not on a cell by cell basis.

Code: Select all

Sheets = ThisComponent.Sheets
Sheet = Sheets.getByIndex(2)
Annotations = Sheet.getAnnotations()
Cell = Sheet.getCellrangeByName("E7")
CellAddr = Cell.CellAddress
Annotations.insertNew(CellAddr, "The new annotation text")
Cell.Annotation.isVisible = True
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
ikw_chen
Posts: 17
Joined: Tue Apr 12, 2011 4:03 pm

Re: Calc - Insert Comment to Cell

Post by ikw_chen »

Hi FJCC,

Thanks so much for your quick reply, It works fine with below code:

Code: Select all

XCellAddressable xCellAddr;
CellAddress aCellAdd;
							
xCellAddr = (XCellAddressable)UnoRuntime.queryInterface(XCellAddressable.class, xCell);
aCellAdd = xCellAddr.getCellAddress();
							
// insert an annotation
XSheetAnnotationsSupplier xAnnotationsSupp = (XSheetAnnotationsSupplier) UnoRuntime.queryInterface(XSheetAnnotationsSupplier.class, xSheet);
XSheetAnnotations xAnnotations = xAnnotationsSupp.getAnnotations();
xAnnotations.insertNew(aCellAdd, "This is comment");
Regards,
Openoffice 3.3 on WinXP
Post Reply