How to set the number of decimal places in a Numbers cell using AppleScript?

I can set the cell format in the Numbers table using:

tell application "Numbers" activate tell document 1 tell active sheet set the selectedTable to ¬ (the first table whose class of selection range is range) end tell tell selectedTable tell column "J" set the format of cell 3 to number end tell end tell end tell end tell 

But how to set the number of decimal places of a cell?

+5
source share
3 answers

Unfortunately, the AppleScript Numbers dictionary does not support decimal places, however you can do this using the graphical interface.

Since GUI scripts are highly software version dependent, this is for Numbers 3.6.2

 tell application "Numbers" activate tell document 1 tell active sheet set the selectedTable to ¬ (the first table whose class of selection range is range) end tell tell selectedTable tell column "J" set the format of cell 3 to number end tell end tell end tell end tell tell application "System Events" tell process "Numbers" tell radio group 1 of window 1 if value of radio button "Cell" is 0 then click radio button "Cell" repeat until value of radio button "Cell" is 1 delay 0.2 end repeat end if end tell tell text field 1 of scroll area 4 of window 1 set value of attribute "AXFocused" to true set value to "2" keystroke return end tell end tell end tell 

In a system language other than English, the literal string Cell can be localized.

+2
source

Unfortunately, I don't have numbers, so I can't look directly at the dictionary, but theoretically you should have a property for the cell for decimal places.

This page talks about how to manually change decimal places in an application. Thus, it would be wise that you should have similar capabilities in a script.

You tried to do something in this direction ...

 tell application "Numbers" tell document 1 tell selectedTable tell column "J" set props1 to properties of cell 3 set props2 to properties of format of cell 3 end tell end tell end tell end tell 

See what props1 and props2 contain in the previous code examples. If you're lucky, one of them will have a link to "decimal places" (or something similar). Sorry for any errors in my code, as I mentioned, I don't have numbers to actually check them out.

+2
source

Unfortunately, I believe this is not possible, at least not with Numbers v3.6.2. The Numbers dictionary shows that the Decimal property is not available for the cell or range classes

Taking a script and executing it:

  tell application "Numbers" activate tell document 1 tell active sheet set the selectedTable to ¬ (the first table whose class of selection range is range) end tell tell selectedTable tell column "J" set the format of cell 3 to number get properties of cell 3 end tell end tell end tell end tell 

Displays properties:

 {vertical alignment:top, row:row "3" of table 1 of sheet 1 of document id "6F1021A0-BA54-47A2-A2DE-15B7E8DAFCED" of application "Numbers", class:cell, font name:"Helvetica", formatted value:"1.2345E+02", background color:missing value, formula:missing value, name:"J3", text wrap:true, text color:{0, 0, 0}, alignment:auto align, column:column "J" of table 1 of sheet 1 of document id "6F1021A0-BA54-47A2-A2DE-15B7E8DAFCED" of application "Numbers", format:scientific, font size:10.0, value:123.45} 

.. none of which looks like a decimal place property: - (

+2
source

All Articles