Skip to content

Instantly share code, notes, and snippets.

@Zenkly
Created April 19, 2018 07:27
Show Gist options
  • Save Zenkly/876e61975c6d0983383a28bda8efbe52 to your computer and use it in GitHub Desktop.
Save Zenkly/876e61975c6d0983383a28bda8efbe52 to your computer and use it in GitHub Desktop.
sub AnnotationsNumber
Dim CalcDoc As Object
Dim CalcSheet As Object
Dim AnnotationCell As Object
Dim SheetAnnotations As Object
Dim anAnnotation As Object
Dim Index As Long
CalcDoc = ThisComponent
CalcSheet = CalcDoc.sheets.getByIndex(0)
SheetAnnotations = CalcSheet.annotations
AnnotationCell = CalcSheet.getCellByPosition(1, 5)
SheetAnnotations.insertNew(AnnotationCell.cellAddress, "This is an annotation")
AnnotationCell.annotation.isVisible = true
AnnotationCell.annotation.annotationShape.fillColor = rgb(100, 0, 50)
AnnotationCell.annotation.annotationShape.charFontName = "Lobster"
AnnotationCell.annotation.annotationShape.charHeight = 10
AnnotationCell.annotation.String = "hola"
myAnnotation = getAnnotationByCell(AnnotationCell)
myAnnotation.string = "Hi!"
AnnotationCell = CalcSheet.getCellByPosition(1, 20)
Index = getIndexAnnotationByCell(AnnotationCell)
if (Index <> -1) Then
myAnnotation = SheetAnnotations.getByIndex(Index)
myAnnotation.isVisible = true
myAnnotation.string = "Bye!"
End If
End sub
Sub AutomaticAnnotations
Dim CalcDoc As Object
Dim CalcSheet As Object
Dim AgeCell As Object
Dim SheetAnnotations As Object
Dim CellAnnotation As Object
CalcDoc = ThisComponent
CalcSheet = CalcDoc.sheets.getByIndex(0)
SheetAnnotations = CalcSheet.annotations
AgeCell = CalcSheet.getCellByPosition(1, 0)
Select Case AgeCell.getType()
Case com.sun.star.table.CellContentType.VALUE
Flags = com.sun.star.sheet.CellFlags.ANNOTATION
AgeCell.clearContents(Flags)
Case Else
SheetAnnotations.insertNew(AgeCell.cellAddress, "This must be a number")
AgeCell.annotation.isVisible = true
AgeCell.annotation.annotationShape.fillColor = rgb(100, 0, 50)
AgeCell.annotation.annotationShape.charFontName = "Lobster"
AgeCell.annotation.annotationShape.charHeight = 10
End Select
End Sub
Function getIndexAnnotationByCell(AgeCell As Object) As Long
Dim result As Long
Dim SheetAnnotations As Object
Dim annotationIndex As Long
Dim anAnnotation As Object
Dim isFound As Boolean
SheetAnnotations = AgeCell.spreadSheet.annotations
While ((annotationIndex < SheetAnnotations.count) and (not isFound))
anAnnotation = SheetAnnotations.getByIndex(annotationIndex)
isFound = ((anAnnotation.position.row = AgeCell.cellAddress.row) and (anAnnotation.position.column = AgeCell.cellAddress.column))
If (isFound) Then
result = annotationIndex
End If
annotationIndex = annotationIndex + 1
Wend
if(not isFound) Then
result = -1
End If
getIndexAnnotationByCell = result
End Function
Function getAnnotationByCell(AgeCell As Object) As Object
Dim result As Object
Dim SheetAnnotations As Object
Dim annotationIndex As Long
Dim anAnnotation As Object
Dim isFound As Boolean
SheetAnnotations = AgeCell.spreadSheet.annotations
While ((annotationIndex < SheetAnnotations.count) and (not isFound))
anAnnotation = SheetAnnotations.getByIndex(annotationIndex)
isFound = ((anAnnotation.position.row = AgeCell.cellAddress.row) and (anAnnotation.position.column = AgeCell.cellAddress.column))
If (isFound) Then
result = anAnnotation
End If
annotationIndex = annotationIndex + 1
Wend
if(not isFound) Then
result = NOTHING
End If
getAnnotationByCell = result
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment