4

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.

1 Answers1

1

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.

CRGreen
  • 3,406
  • 1
  • 14
  • 24
  • I'll experiment with this, but I'm skeptical. I'm filling a detailed formatted page with string data (a CMS-1500 insurance claim form to be specific) for printing. I placed a full-size pic of the CMS-1500 on the Numbers sheet, and superimposed a table with tiny cells. I then merged cells to overlay the form entry fields, carefully formatting the merged ranges to the form's field specs. Unless there's a way to retain this formatting, I don't think I want to programmatically merge the cells; I want them merged to start with. Thanks though. – Buffalo Chip May 30 '20 at 03:12
  • @BuffaloChip - Yes, you should experiment with this - with a nice test document or have adequate backup of course. I found this solution; it seemed to keep the formatting of the previous merge. Now that we know more about what you're trying to accomplish, we can fill in some gaps, if necessary. But my reply is a solution for the problem you posted. And yes, you'll have to have the merged cells as an additional set of variables. Not difficult to set up. – CRGreen May 30 '20 at 06:25
  • 1
    My skepticism was unfounded — it works. As you say, it keeps the formatting. This approach prepends the new value to the existing value in the merged range instead of replacing it. But that's easily fixed by clearing the ranges first. Thanks again. – Buffalo Chip May 30 '20 at 19:02