Brother Jack

Q: Hiding or unhiding table rows with AppleScript?

I have a large table in Numbers, and I want to sometimes view the entire table, and sometimes select a group of rows to hide or unhide, to make viewing the data more convenient.

 

Selecting the numerous rows to hide is tedious (there are many, and they are not contiguous).  So I would like to use AppleScript to do this.  But in the Numbers AppleScript dictionary, I don't see any way to apply a 'hidden' attribute to either rows, columns, or ranges.  Is there some trick I'm missing?  Or does this just not exist in the current implementation?

 

Thanks

Mac OS X (10.7.5)

Posted on Mar 18, 2016 1:29 PM

Close

Q: Hiding or unhiding table rows with AppleScript?

  • All replies
  • Helpful answers

  • by SGIII,Apple recommended

    SGIII SGIII Mar 21, 2016 2:51 PM in response to Brother Jack
    Level 6 (10,647 points)
    Mac OS X
    Mar 21, 2016 2:51 PM in response to Brother Jack

    As far as I know you can't hide a row or set the height to 0 using AppleScript, though I suggested that a while back via Numbers > Provide Numbers Feedback in the menu.

     

    What you could do is filter the table to hide the rows, probably by adding a filter column designating which rows you want to see (or, conversely, hide).  That filter can be turned on and off via AppleScript using the table's filtered property, though it would probably be easier to do it via the built-in interface.

     

    SG

  • by Barry,Apple recommended

    Barry Barry Mar 21, 2016 2:51 PM in response to Brother Jack
    Level 7 (32,271 points)
    Mar 21, 2016 2:51 PM in response to Brother Jack

    Adding to what SGIII said...

    You can use a pair of columns to determine which rows are shown. In the example below, every row is a member of four groups (of a total of 10), identified by the letters A through J. All rows are members of group A, Some rows are members of each of the other groups.

     

    Entering an upper case letter from the A-J set in cell D1 generates a "hide" label in Column C of rows not containing the letter in column D, and a number corresponding to the position of the letter in rows where it is found in the group in column D. The filter setting shown next to the table hides all rows where C does not contain a number.

    Screen Shot 2016-03-19 at 12.06.53 AM.png

    Column C contains the formula below, entered into C2, and filled down from there to the end of the column.

    C2: =IFERROR(FIND(D$1,D),"Hide")

     

    I've used single letters to identify the groups only because single letters are easier to generate than words. Any string of characters may be used as a group name, providing it exactly matches the search string entered n D1, AND it does not exist as a subset of other group names in the list (eg. the search string "WAY" would show rows where the group names were HIWAY SUBWAY WAYFARER and, if no separator was used between groupnames, a row containing JACKDAW and AYLMER without separation ( JACKDAWAYLMER ).

     

    Fegards,

    Barry

  • by aquilafedele,

    aquilafedele aquilafedele Sep 10, 2016 1:46 AM in response to Brother Jack
    Level 1 (16 points)
    Sep 10, 2016 1:46 AM in response to Brother Jack

    It is possible to do that using GUI Scripting.

     

    You can set the range in your code and then call the handler. In a similar way it's possible to show hidden rows/columns.

     

     

    tell application "Numbers"

      activate

      set newDocument to make new document

      tell front sheet of newDocument

      delete every table

      delay 1

     

      set newTable to make new table with properties {column count:8, row count:8, header row count:1, header column count:1}

     

      set cellsToHide to "B3:D6"

     

      -- Hide rows

      my hideCells((name of newTable), cellsToHide, 1)

      end tell

    end tell

     

    -- Hide given cells

    on hideCells(tableName, rangeName, hideRow)

      -- range name is the range to select rows or columns (the ENTIRE rows or columns)

      -- hideRow is 1 if you want to hide rows, otherwise hide columns

      tell application "Numbers"

      activate

      tell front sheet of front document

      tell table tableName to set selection range to range rangeName

      tell application "System Events"

      tell process "Numbers"

      set frontmost to true

      delay 1

     

      -- Check if hide rows or columns

      if hideRow is 1 then

      click menu item 22 of menu "Table" of menu bar item "Table" of menu bar 1 -- hide rows

      else

      click menu item 24 of menu "Table" of menu bar item "Table" of menu bar 1 -- hide columns

      end if

      end tell

      end tell

      end tell

      end tell

    end hideCells

  • by t quinn,

    t quinn t quinn Sep 10, 2016 7:10 AM in response to Brother Jack
    Level 5 (5,012 points)
    Mac OS X
    Sep 10, 2016 7:10 AM in response to Brother Jack

    Hi Brother,

     

    I want to second SG's suggestion for a filter. If you think you can describe wht you want to hide to applescript you should be able to do it in a formula.

     

    Check out this approach.

    Change data displayed via Pop-up menu

    If you are having specific questions about the logic feel free to post them here.

     

    This post by Badunit was my inspiration for approach.                                

     

    quinn

     

    edit: I should check the origin date for posts.

  • by SGIII,

    SGIII SGIII Sep 10, 2016 11:06 AM in response to aquilafedele
    Level 6 (10,647 points)
    Mac OS X
    Sep 10, 2016 11:06 AM in response to aquilafedele

    Hi aquilafidele,

     

    Thanks for posting that GUI-scripting solution!

     

    SG