Hi,

To add/modify an annotation, you have to use the collection of annotations of a 
spreadsheet :

option explicit

sub main

        dim doc as object
        dim aSheet as object
        dim aCell as object
        dim annotations as object
        dim myAnnotation as object
        
        doc = thisComponent
        aSheet = doc.sheets.getByIndex(0)
        
        'insert a new annotation
        ''''''''''''''''''''''''
        aCell = aSheet.getCellByPosition(0, 0)
        annotations = aSheet.annotations
        annotations.insertNew(aCell.cellAddress, "Text content")
        
        'modify an existing annotation
        ''''''''''''''''''''''''''''''
        'to modify an annotation, we can't use cell's pseudo-property 
"annotation" which is read-only
        myAnnotation = _getAnnotationByCell(aCell)
        myAnnotation.isVisible = true
        myAnnotation.annotationShape.fillColor = rgb(148, 0, 107)
        myAnnotation.annotationShape.charFontName = "Tahoma"
        myAnnotation.annotationShape.charHeight = 12

end sub

function _getAnnotationByCell(aCell as object) as object

        dim result as object
        dim annotations as object
        dim annotationIndex as long
        dim anAnnotation as object
        dim isFound as boolean
        
        annotations = aCell.spreadSheet.annotations
        while ((annotationIndex < annotations.count) and (not isFound))
                anAnnotation = annotations.getByIndex(annotationIndex)
                isFound = ((anAnnotation.position.row = aCell.cellAddress.row) 
and (anAnnotation.position.column = aCell.cellAddress.column))
                if (isFound) then
                        result = anAnnotation
                end if
                annotationIndex = annotationIndex + 1
        wend
        
        _getAnnotationByCell = result

end function

Regards,
Thibault Vataire



----- Mail Original -----
De: "Phil Hibbs" <[email protected]>
À: [email protected]
Envoyé: Samedi 10 Juillet 2010 22:17:38
Objet: [api-dev] Adding a Comment in Calc

How do I add a Comment to a cell using a macro? I haven't learned any
specific macro languages yet, but I've played around with some recorded
macros, and the recording of adding a Comment does nothing. I am proficient
with Excel VBA and am trying to learn to apply the same techniques to OOo.

Phil Hibbs.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to