[Solved] Macro to obtain row column like Ctrl-End does

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
norisezp
Posts: 3
Joined: Sat Apr 16, 2016 5:51 am

[Solved] Macro to obtain row column like Ctrl-End does

Post by norisezp »

I need a basicmacro in Calc that will get the row and column of the last filled cell like ctrl+end does, but without moving the cursor. Any ideas?
Last edited by norisezp on Sat Apr 16, 2016 5:13 pm, edited 1 time in total.
OpenOffice 2.4 on Ubuntu 9.04
FJCC
Moderator
Posts: 9274
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Macro to obtain row column like Ctrl-End does

Post by FJCC »

Try something like this

Code: Select all

  oSheets = ThisComponent.getSheets()
  oSheet = oSheets.getByName("Sheet1")
  oCurs = oSheet.createCursor()
  
  oCurs.gotoEndOfUsedArea(False)
  print oCurs.AbsoluteName
  print " Column Index = " & oCurs.RangeAddress.StartColumn & " Row Index = " & OCurs.RangeAddress.StartRow
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
norisezp
Posts: 3
Joined: Sat Apr 16, 2016 5:51 am

Re: Macro to obtain row column like Ctrl-End does

Post by norisezp »

Thank you. Question: If code gets serially reused, is it necessary to delete the oCurs object on each trip through, to avoid filling up the heap and/or stack?
OpenOffice 2.4 on Ubuntu 9.04
FJCC
Moderator
Posts: 9274
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Macro to obtain row column like Ctrl-End does

Post by FJCC »

Once you create the cursor with oCurs = oSheet.createCursor(), you can reuse that object as much as you want. You don't need to create a new cursor for each use. For example, if you have a loop in your code, put the createCursor() statement outside of the loop and the commands to move the cursor inside of the loop. Is that the sort of use you are asking about?
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
norisezp
Posts: 3
Joined: Sat Apr 16, 2016 5:51 am

Re: Macro to obtain row column like Ctrl-End does

Post by norisezp »

It's actually in a function, but I can make it global easily enough. Thank you very much. I'll punch he Answered key.
OpenOffice 2.4 on Ubuntu 9.04
Post Reply