creating mailing labels using data merge between Numbers and Pages

I am trying to run scripts I found on this community chat (specifically this one: https://discussions.apple.com/thread/252034075) but i keep getting error messages when i try to run the scripts. I double checked system to make sure that the editor had proper permissions, that looks right. But I just can't get any of the scripts to work. I have downloaded Avery template for 6570; only 1 Pages file is open and only 1 Numbers spreadsheet is open. Any ideas to resolve would be greatly appreciated! (I do not want to use Contacts for this purpose.)

MacBook Pro 13″, macOS 10.13

Posted on Dec 8, 2021 4:36 PM

Reply

Similar questions

6 replies

Dec 9, 2021 4:00 PM in response to SGIII

Hello SG! Thank you for engaging! I was finally able to get it to work!! I started with your script, worked well! Then added my Pages (using different Avery template), your script and table - it worked! Last test was using my table, my Pages and your script - it worked well!


However my table was formatted differently than yours, so the output was weird. My next options were to either jam my table into yours, or preferably, modify your code to work with my table. That was where I kept failing. The problem ended up not being my changes to your code, but the fact that I had more than 1 page of labels to print, and it would give me an error message that made no sense (it wasn't nicely saying that I needed to have a second formatted page in the document).


So after several more readings of your original post, I happened upon someone's (I think yours!) comment about needing to add more pages to the Pages file itself if the spreadsheet was larger than one page of labels. Once I stumbled on that, added a second formatted page, then the modified script worked! Thank you so much for replying though, because had I not been able to get it to work, you would have been the likely one to see where I was going wrong. In the end, it was your ZIP package that has allowed me to print labels without using MS products!! Thank you!!

Dec 8, 2021 4:42 PM in response to antarcticgecko

I can't directly help with that but you may want to consider another method that works very well for me and does not involve using Pages.

First use Numbers File menu and export the Numbers spreadsheet to Excel format.

Then use an internet browser and go to https://www.avery.com/software/design-and-print/ and click the "Start Designing" button there. It will lead you through a series of prompts and allow you to merge the Excel spreadsheet and you can then print the labels to your printer directly from that website.

Dec 9, 2021 4:35 PM in response to SGIII

I loved your code - the beauty is it's simplicity! I tweaked it to this because my table is quite simple:


const cols = {fname:"B", lname:"A", mname:"G", street1:"C", street2:"H",

city:"D", state: "E", code:"F", salut:"I", usr1:"J", usr2:"K"};


// change column letters between " " above to match Numbers table

// have Pages labels template open and frontmost before running script

// number of boxes in template must equal or exceed table rows

// compile again (hit the hammer) before rerunning


Object.keys(cols).forEach(key => cols[key]="ABCDEFGHIJK".indexOf(cols[key]));


const table = Application("Numbers").documents[0].activeSheet.tables[0],

doc = Application("Pages").documents[0],

notNull = value => value !== null; //function for filter()


for(var i=1;i<table.rowCount();i++) {


let rv = table.rows[i].cells.formattedValue(); // values in this row


let name = [rv[cols.lname]];

let street = [rv[cols.street1]];

let ctyst = [rv[cols.city],rv[cols.state]].join(", ");

let zcode = [rv[cols.code]];

let nameaddr = [name,street,ctyst,zcode].join("\n");


let lbltxt = doc.textItems[i-1].objectText;

lbltxt.set(nameaddr);

}


It works like a charm!

Thank you!! :D

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.

creating mailing labels using data merge between Numbers and Pages

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