[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: 1
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: 5091
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.
Cheers
David
OS - Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.2.2.2; SlackBuild for 24.2.2 by Eric Hameleers
User avatar
karolus
Volunteer
Posts: 1160
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 7.6 flatpak on Debian 12 (Bookworm) (on RaspberryPI4)
User avatar
DiGro
Posts: 177
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: 2791
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
MrProgrammer
Moderator
Posts: 4913
Joined: Fri Jun 04, 2010 7:57 pm
Location: Wisconsin, USA

Re: Macro button for hide/unhide rows in Calc

Post by MrProgrammer »

1eSkip wrote: Sat Apr 20, 2024 3:43 am 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
This post seems to have been created by a language transation program. I will interpret it as:
1eSkip wrote: Sat Apr 20, 2024 3:43 am I am trying to create a macro for a button to show or hide specific rows. For columns, I have already done this. Now I want to show or hide rows.
There is no need to learn the complex OpenOffice programming interface if you record a macro:
• Tools → Macros → Record
• Select the specific rows to show or hide using the Name Box
• Format → Rows → Show    or    Format → Rows → Hide
• Stop Recording
• Give your macro a name and save it.
[Tutorial] Favorite Recorded Calc Macros

For example, to show or hide rows 5 through 8 type A5:A8 in the Name Box and press Enter.

Record macros for each specific set of rows, one to hide and one to show. You can run your macros using Tools → Macros → Run or by using this tutorial. I would think creating a toolbar to run the macros is the best method for this situation.
[Tutorial] Binding a macro: Shortcut key, menu or toolbar

karolus wrote: Sat Apr 20, 2024 7:32 am Select Range A14:A17
hit F12
choose [x]Rows
⇒ok
Select specific rows → Data → Group and Outline → Group → Rows → OK is another simple method which avoids the need to learn the OpenOffice programming interface. It creates + and - buttons on the left side of the screen which you can use to hide or show rows. Use the 1 above to hide all groups and the 2 to show all groups.


If this solved your problem please go to your first post use the Edit button and add [Solved] to the start of the Subject field. Select the green checkmark icon at the same time.
Mr. Programmer
AOO 4.1.7 Build 9800, MacOS 13.6.3, iMac Intel.   The locale for any menus or Calc formulas in my posts is English (USA).
User avatar
Lupp
Volunteer
Posts: 3553
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.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
User avatar
robleyd
Moderator
Posts: 5091
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 
Cheers
David
OS - Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.2.2.2; SlackBuild for 24.2.2 by Eric Hameleers
Post Reply