Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
ikw_chen
Posts: 17 Joined: Tue Apr 12, 2011 4:03 pm
Post
by ikw_chen » Sun Jun 05, 2011 4:04 pm
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
Zizi64
Volunteer
Posts: 11363 Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary
Post
by Zizi64 » Sun Jun 05, 2011 7:48 pm
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
Post
by FJCC » Sun Jun 05, 2011 9:41 pm
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
Post
by ikw_chen » Mon Jun 06, 2011 6:23 pm
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