Difference between revisions of "Documentation/DevGuide/Spreadsheets/Cell Annotations"
From Apache OpenOffice Wiki
< Documentation | DevGuide
OOoWikiBot (Talk | contribs) m (FINAL VERSION FOR L10N) |
|||
Line 31: | Line 31: | ||
The following example inserts an annotation and makes it permanently visible. | The following example inserts an annotation and makes it permanently visible. | ||
<!--[SOURCE:Spreadsheet/SpreadsheetSample.java]--> | <!--[SOURCE:Spreadsheet/SpreadsheetSample.java]--> | ||
− | + | <syntaxhighlight lang="java"> | |
public void doAnnotationSample( | public void doAnnotationSample( | ||
com.sun.star.sheet.XSpreadsheet xSheet, | com.sun.star.sheet.XSpreadsheet xSheet, | ||
Line 55: | Line 55: | ||
xAnnotation.setIsVisible(true); | xAnnotation.setIsVisible(true); | ||
} | } | ||
− | + | </syntaxhighlight> | |
{{PDL1}} | {{PDL1}} | ||
[[Category:Documentation/Developer's Guide/Spreadsheet Documents]] | [[Category:Documentation/Developer's Guide/Spreadsheet Documents]] |
Latest revision as of 15:33, 3 January 2021
A spreadsheet cell may contain one annotation that consists of simple unformatted Text.
This service com.sun.star.sheet.CellAnnotation represents an annotation. It implements interfaces to manipulate the contents and access the source cell.
- The interface com.sun.star.sheet.XSheetAnnotation implements methods to query data of the annotation and to show and hide it. This interface is returned by the method
getAnnotation()
of the interface com.sun.star.sheet.XSheetAnnotationAnchor. - The method
getParent()
of the interface com.sun.star.container.XChild returns the cell object that contains the annotation. - The interface com.sun.star.text.XSimpleText modifies the text contents of the annotation. See Editing Text for details.
It is possible to access the annotations through a container object from the spreadsheet or directly from a cell object.
- The method
getAnnotations()
of the interface com.sun.star.sheet.XSheetAnnotationsSupplier returns the interface com.sun.star.sheet.XSheetAnnotations of the annotations collection of this spreadsheet. - The method
getAnnotation()
of the interface com.sun.star.sheet.XSheetAnnotationAnchor returns the interface com.sun.star.sheet.XSheetAnnotation of an annotation object.
The service com.sun.star.sheet.CellAnnotations represents the collection of annotations for the spreadsheet and implements two interfaces to access the annotations.
- The interface com.sun.star.sheet.XSheetAnnotations is derived from com.sun.star.container.XIndexAccess to access and remove annotations through their index. The method
insertNew()
attaches a new annotation to a cell. - The method
createEnumeration()
of the interface com.sun.star.container.XEnumerationAccess creates an enumeration object, represented by the service com.sun.star.sheet.CellAnnotationsEnumeration, to access the annotations sequentially.
The following example inserts an annotation and makes it permanently visible.
public void doAnnotationSample( com.sun.star.sheet.XSpreadsheet xSheet, int nColumn, int nRow ) throws RuntimeException, Exception { // create the CellAddress struct com.sun.star.table.XCell xCell = xSheet.getCellByPosition(nColumn, nRow); com.sun.star.sheet.XCellAddressable xCellAddr = (com.sun.star.sheet.XCellAddressable) UnoRuntime.queryInterface(com.sun.star.sheet.XCellAddressable.class, xCell); com.sun.star.table.CellAddress aAddress = xCellAddr.getCellAddress(); // insert an annotation com.sun.star.sheet.XSheetAnnotationsSupplier xAnnotationsSupp = (com.sun.star.sheet.XSheetAnnotationsSupplier) UnoRuntime.queryInterface( com.sun.star.sheet.XSheetAnnotationsSupplier.class, xSheet); com.sun.star.sheet.XSheetAnnotations xAnnotations = xAnnotationsSupp.getAnnotations(); xAnnotations.insertNew(aAddress, "This is an annotation"); // make the annotation visible com.sun.star.sheet.XSheetAnnotationAnchor xAnnotAnchor = (com.sun.star.sheet.XSheetAnnotationAnchor) UnoRuntime.queryInterface( com.sun.star.sheet.XSheetAnnotationAnchor.class, xCell); com.sun.star.sheet.XSheetAnnotation xAnnotation = xAnnotAnchor.getAnnotation(); xAnnotation.setIsVisible(true); }
Content on this page is licensed under the Public Documentation License (PDL). |