Reputation: 31
I want to count the occurrences of yellow, orange, green, and red within the selection using a LibreOffice Basic macro. I have been to this Stackoverflow question, but it doesn't work for me.
Here's the code:
Sub Main
dim selection,cell as Object
dim i,j as integer
selection = ThisComponent.getCurrentController().getSelection()
for i=selection.RangeAddress.StartRow to selection.RangeAddress.EndRow
for j=selection.RangeAddress.StartColumn to Selection.RangeAddress.EndColumn
cell = ThisComponent.Sheets(0).getCellByPosition(i,j)
print cell.CellBackColor
rem TODO: Count colors
next
next
End Sub
It aways says -1
except when the cell color is black, then it says 0
. What am I doing wrong?
Upvotes: 1
Views: 2808
Reputation: 31
I switched i
and j
in getCellByPosition(i,j)
. It should actually be getCellByPosition(j,i)
.
Upvotes: 2