Page 1 of 1

[Solved] Calc - Insert Comment to Cell

PostPosted: Sun Jun 05, 2011 4:04 pm
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   Expand viewCollapse view
XSpreadsheet xSheet = (XSpreadsheet)UnoRuntime.queryInterface(XSpreadsheet.class, oSheet);

xCell = nameRange.getCellByPosition(0, 1);

xCell.setValue
xCell.setFormula


Thanks for advices!

Re: Calc - Insert Comment to Cell

PostPosted: Sun Jun 05, 2011 7:48 pm
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....

Re: Calc - Insert Comment to Cell

PostPosted: Sun Jun 05, 2011 9:41 pm
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   Expand viewCollapse view
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

Re: Calc - Insert Comment to Cell

PostPosted: Mon Jun 06, 2011 6:23 pm
by ikw_chen
Hi FJCC,

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

Code: Select all   Expand viewCollapse view
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,