Page 1 of 1

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

Posted: Sat Apr 20, 2024 3:43 am
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

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

Posted: Sat Apr 20, 2024 6:40 am
by robleyd
Can I find too little information?
You may find Andrew Pitonyak's books on OO macros a useful resource.

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

Posted: Sat Apr 20, 2024 7:32 am
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 

Re: Macro button for hide/unhide rows in Calc

Posted: Sat Apr 20, 2024 1:46 pm
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.

Re: Macro button for hide/unhide rows in Calc

Posted: Sat Apr 20, 2024 7:13 pm
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

Re: Macro button to hide/unhide rows in Calc

Posted: Tue Apr 23, 2024 10:09 pm
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.

Re: Macro button to hide/unhide rows in Calc

Posted: Wed Apr 24, 2024 1:28 am
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