AppleScript to adjust row/height dimensions

I want the cells of a table to resize uniformly to fully fill its sheet's printed page on both the x and y axes.



There doesn't seem to be a way to adjust the dimensions of a table's cells from the print view, meaning any number of trips between views to select all the rows/columns and fiddle about with the size adjuster.


User uploaded file
I want the columns to fill the printed page without spilling over into the next page



I wrote an AppleScript that lets me choose the active sheet's first table's cells' height or width, then adjust the chosen dimension of the cells by any uniform amount.



It still takes a bit of trail and error, but there's no need to select all the rows/columns and fiddle about with size adjuster. (The 'Row & Column Size' text fields are of no use when the cells have variable heights/widths.)



Does anyone have alternative/improved solution to this problem? If not, the code's here for anyone to use/customise.



set _dimensionText to text returned of _displayDialog("Table's Cells' dimension?", "Change Cells' Height or Width", "height") if _dimensionText is not in {"height", "h", "width", "w"} then return try           set _amount to (text returned of _displayDialog("Amount to add/substract?", "Change Cells' Height or Width", "2")) as real on error a number b           return end try tell application "Numbers"           activate           delay 0.5           set _activeSheet to active sheet of document 1           set _table to table 1 of _activeSheet           if _dimensionText is in {"height", "h"} then                     set _dimensions to rows of _table                     repeat with _dimension in _dimensions                               set _height to height of _dimension                               set height of _dimension to (_height + _amount)                     end repeat           else                     set _dimensions to columns of _table                     repeat with _dimension in _dimensions                               set _width to width of _dimension                               set width of _dimension to (_width + _amount)                     end repeat           end if end tell on _displayDialog(_message, _title, _defaultAnswer)           set _dialog to display dialog _message with title _title default answer _defaultAnswer end _displayDialog

Posted on Apr 12, 2014 6:05 AM

Reply
2 replies

Apr 12, 2014 6:56 PM in response to philostein

Thanks for this. To have the script to act on the currently selected table in the active sheet rather than be hardwired to always act on the first table in the active sheet (for situations where you may have more than one table in a sheet you want to print) then you can change:


set _table to table 1 of _activeSheet


To:


set _table to first table of _activeSheet whose class of selection range is range



SG

Apr 12, 2014 7:27 PM in response to SGIII

Great, I added that line. Also, I decided to change the dimensions of cells by a percentage of their original dimensions. That way, rows/columns keep their relative size when compared to each other. So:


set height of _dimension to (_height + _amount)


becomes:


set height of _dimension to (_height * (1 + _amount / 100))




Here's the updated script:




set _dimensionText to text returned of _displayDialog("Table's Cells' dimension?", "Change Cells' Height or Width", "height") if _dimensionText is not in {"height", "h", "width", "w"} then return try      set _amount to (text returned of _displayDialog("Percentage increase/decrease?", "Change Cells' Height or Width", "20")) as real on error a number b      return end try tell application "Numbers"           activate      delay 0.5           set _activeSheet to active sheet of document 1      set _table to first table of _activeSheet whose class of selection range is range                if _dimensionText is in {"height", "h"} then           set _dimensions to rows of _table           repeat with _dimension in _dimensions                set _height to height of _dimension                set height of _dimension to (_height * (1 + _amount / 100))           end repeat      else           set _dimensions to columns of _table           repeat with _dimension in _dimensions                set _width to width of _dimension                set width of _dimension to (_width * (1 + _amount / 100))           end repeat      end if end tell on _displayDialog(_message, _title, _defaultAnswer)      set _dialog to display dialog _message with title _title default answer _defaultAnswer end _displayDialog

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

AppleScript to adjust row/height dimensions

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.