Cell Annotations

From Apache OpenOffice Wiki
Jump to: navigation, search

A spreadsheet cell may contain one annotation that consists of simple unformatted Text.

Cell annotations

This service com.sun.star.sheet.CellAnnotation represents an annotation. It implements interfaces to manipulate the contents and access the source cell.

It is possible to access the annotations through a container object from the spreadsheet or directly from a cell 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 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();
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages