[Solved] Macro button to hide/unhide rows in Calc

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
1eSkip
Posts: 2
Joined: Fri Apr 19, 2024 6:34 pm

[Solved] Macro button to hide/unhide rows in Calc

Post by 1eSkip »

588 / 5.000
Vertaalresultaten
Vertaalresultaat
Good day everyone. I am trying to create a macro for a button to show or hide specific Rules for columns, I have already done this. But for rules. Can I find too little information? Who oh who would want and be able to help me. I would be gratefull.

this is what i tried. This is derived from my macro that hides a column via a button.

Code: Select all

REM ***** BASIC *****

sub toggle_Rows_1ePart
     doc = thisComponent
     sheet = doc.CurrentController.ActiveSheet
     rows = sheet.rows("14,15,16,17")
     rows.IsVisible = not rows.IsVisible
end sub
Last edited by robleyd on Wed Apr 24, 2024 2:47 am, edited 1 time in total.
Reason: Tagged [Solved]. Add green tick
LibreOffice 24.2
User avatar
robleyd
Moderator
Posts: 5239
Joined: Mon Aug 19, 2013 3:47 am
Location: Murbko, Australia

Re: a macro button for hide/unhide rows in calc

Post by robleyd »

Can I find too little information?
You may find Andrew Pitonyak's books on OO macros a useful resource.
Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.8.2.1; SlackBuild for 24.8.2 by Eric Hameleers
---------------------
Roses are Red, Violets are Blue
Unexpected '{' on line 32
.
User avatar
karolus
Volunteer
Posts: 1197
Joined: Sat Jul 02, 2011 9:47 am

Re: a macro button for hide/unhide rows in calc

Post by karolus »

Hallo

Select Range A14:A17
hit F12
choose [x]Rows
⇒ok

now you will find left of Row 14 a tiny Button to hide|unhide Rows 14 to 17


PS: working counterpart to your NOT working basic! … in python:

Code: Select all

def toggle_row_14_17(*_):
    doc = XSCRIPTCONTEXT.getDocument()
    sheet = doc.CurrentController.ActiveSheet
    rows = sheet[13:17, 0 ].Rows
    rows.IsVisible = not rows.IsVisible 
AOO4, Libreoffice 6.1 on Rasbian OS (on ARM)
Libreoffice 7.4 on Debian 12 (Bookworm) (on RaspberryPI4)
Libreoffice 24.8… flatpak on Debian 12 (Bookworm) (on RaspberryPI4)
User avatar
DiGro
Posts: 192
Joined: Mon Oct 08, 2007 1:31 am
Location: Hoorn NH, The Netherlands

Re: Macro button for hide/unhide rows in Calc

Post by DiGro »

You were almost there.

Try this one:

Code: Select all

Sub hideRows14_17()
oDoc=ThisComponent
oSheet=oDoc.CurrentController.ActiveSheet
myRange=oSheet.getCellRangeByPosition(,13,,16)
myRange.Rows.IsVisible=false
End Sub
Mind you getCellRangeByPosition takes as arguments (start_column,start_row,end_column,end_row) hence (,13,,16) Rows are zero based.
____________
DiGro

AOO 4.1.15 (Dutch) on Windows 11. Scanned with Ziggo Safe Online (F-Secure)
JeJe
Volunteer
Posts: 2908
Joined: Wed Mar 09, 2016 2:40 pm

Re: Macro button for hide/unhide rows in Calc

Post by JeJe »

Apart from the IDE help file, Pitonyak's free books, searching here - someone's usually already asked a similar question -
there is the MRI Object Inspector which is invaluable.

viewtopic.php?t=49294

this extension is too:

https://extensions.openoffice.org/en/pr ... -ide-tools
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
Lupp
Volunteer
Posts: 3604
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: Macro button to hide/unhide rows in Calc

Post by Lupp »

If, however, the questioner is eager to learn more about using the API in custom code:
Information that may change (here mainly the row range to be treated) should not be hard coded in a Sub if avoidable.
Any FormControl object like the PushButton in this case has a property .Tag which can be used to pass special information to the called code. For the UI (en) this property is circumscribed as "Additional information".
See attached example.
On Windows 10: LibreOffice 24.8.2 and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
User avatar
robleyd
Moderator
Posts: 5239
Joined: Mon Aug 19, 2013 3:47 am
Location: Murbko, Australia

Re: Macro button to hide/unhide rows in Calc

Post by robleyd »

Cross posted at AskLibreOffice

If you cross post, as a courtesy please let us know that you have done so, otherwise it leads to several discussions and a waste of time because several identical answers may be posted by different users.
 Edit: Solved - see the AskLibreOffice link 
Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.8.2.1; SlackBuild for 24.8.2 by Eric Hameleers
---------------------
Roses are Red, Violets are Blue
Unexpected '{' on line 32
.
1eSkip
Posts: 2
Joined: Fri Apr 19, 2024 6:34 pm

Re: Macro button to hide/unhide rows in Calc

Post by 1eSkip »

robleyd wrote: Wed Apr 24, 2024 1:28 am Cross posted at AskLibreOffice

If you cross post, as a courtesy please let us know that you have done so, otherwise it leads to several discussions and a waste of time because several identical answers may be posted by different users.
 Edit: Solved - see the AskLibreOffice link 
Yes the same answer as on the other Forum. Sorry I didn't know this had to be reported, But I see that this message is already marked as resolved. Thank you
LibreOffice 24.2
Post Reply