Search code examples
applescriptapple-numbersapplescript-numbers

Assigning a value to merged cells in Apple Numbers using AppleScript


As part of a longer AppleScript, I'm copying strings from a list variable into ranges of merged cells in a Numbers 10.0 table. E.g., if the list is called form_filler and the first range of merged cells is B6:Y7, I first tried:

set value of cell "B6" to item 1 of form_filler

I thought one addresses merged cells by the top-left cell. But this does something unexpected: it places the string only into cell "B6" and changes the range of merged cells to C6:Y7, excluding the cell I just pasted into. This behavior occurs consistently with different merged cells throughout the table. I then tried:

set value of range "B6:Y7" to item 1 of form_filler

but this returned an error; I can't assign a value to the range.

I'm new to AppleScript, but not programming generally (e.g., Python). What am I missing? Thanks.


Solution

  • It looks like you have to re-merge those cells. Here's code I just tested using my own tell block structure; you should be able to extrapolate from this (if you include your tell block structure I'll edit my code):

    tell application "Numbers"
        set d to sheet 1 of document 1
        tell d
            set value of cell "B6" of table 1 of it to "test"
            merge range "B6:Y7" of table 1 of it
        end tell
    end tell
    

    Not sure if this qualifies as a "work-around", but it seems to work, hopefully w/o introducing other issues.