BASIC+Calc: gotoEndOfUsedArea

Last cell of each sheet of attached Calc is similar.

Why does gotoEndOfUsedArea give the different results ?

Click [ Test Calc BASIC ] on the menu of gotoEndOfUsedArea.ods

[ Fedora 32 Workstation Cinnamon Desktop Spin ] [ LibreOffice 6.2.8.2-2 ]

gotoEndOfUsedArea.ods

What do you mean by “Last cell of each sheet of attached Calc is similar.”?
Well, for both sheets that’s a spreadsheet cell. This may be the only relevant similarity.

In the first sheet the last used cell is F4, and that’s what you get.
In the second sheet the last used cell is AL100, and you get AL15.

That’s a bug imo, though it is exatly what you also get via the UI using Ctrl+End.
Change the color of cell AJ18 to any different shade of yellow, and press Ctrl+End again.
Can you interpret the result without assuming a bug? I didn’t succeed.

My tests were done with LibO V7.0.0.2RC (x64 under Win 10).

I get the same results running the simplified cosd:

Sub Main
doc = ThisComponent
sheets = doc.Sheets()
For Each sheet In sheets
scc = sheet.CreateCursor
scc.gotoStartOfUsedArea(False)
scc.gotoEndOfUsedArea(True)
Print "Used area: " &scc.AbsoluteName
Next sheet
End Sub

See also: LibreOffice: XUsedAreaCursor Interface Reference
The “used cell” and thus UsedArea seem to rely on a concept only occuring related to the interface XUsedAreCursor. This interface has two methods, and only 1 of them is buggy. :slight_smile:

BTW: Ctrl+Pos1 seems to always go to A1. That may NOT be the StartOfUsedArea in the sense of the linked specification. Anyway the UI actions aren’t specified clearly at all, and in this case the names chosen for the actions are funny (To Beginning of File, To End of File).

Dear @Lupp,

Thank you so much for your answer.

Sub ChangeCellRangeBackgroundColorAndCheckLastUsedCellOfSheetGJVC1
	Dim i%, r&, g%, b%, t$, lc%, lr%
	thiscomponent.CurrentController.ActiveSheet = thiscomponent.Sheets.getByName("GJVC1")
	For i = 1 To 200	
		r = Int((255 * Rnd) + 0)    ' Generate random value between 0 and 255.
		g = Int((255 * Rnd) + 0)    ' Generate random value between 0 and 255.
		b = Int((255 * Rnd) + 0)    ' Generate random value between 0 and 255.
		thiscomponent.Sheets.getByName("GJVC1").getCellRangeByPosition(0, 15, 37, 99).CellBackColor = RGB(r, g, b)
		lc = GetLastUsedColumnOfSheet("GJVC1") : lr = GetLastUsedRowOfSheet("GJVC1")
		If lc <> 37 Or lr <> 14 Then
			t = t & "Randomizing : " & i & " : RGB("& r & ", " & g & ", " & b & ") : Last used cell = (" & lc & ", " & lr & ")" & Chr(13)
		End If
	Next
	MsgBox t, , "GJVC1"
End Sub

The result is still the same, (37, 14).

Should I report this bug ?

I actually got what I described, but, of course, I changed the background color of AJ18 via the UI.

It’s your choice if you report a bug.
However, I am afraid you cannot easily describe a reproducible way to get a spreadsheet document showing the issue.
I would suspect your document to have a somehow specific history, probably a CV of occasionally having been saved to an alien format.
No developer will spend a lot of time trying to fix an issue only occurring in one example.
Try to think simpler, and to design your sheets this way.
Anyway: I used the XUsedAreaCursor from time to time, and never experiencee that problem.

Dear @Lupp,

Thank you so much for your concern and your support.

I have already reported TDF#135203, attached with a simple brand new .ods file and sad results.

And as you said, they maybe tried to solve and not yet commented.