Generating reports with Numbers

I’ve set up a sheet in numbers using vlookup linked to a popup menu in one of the cells to generate individual reports for students. So far, so good. I can step through the list to see filtered individual values in a readable format.


I would like to automate “printing” to PDF files so that I don’t have to click on the popup, select the desired value, go to the print menu, select “Save to PDF”, rename the file, pick a save location, repeat for about 500 students.


Is there any way to automate this using either AppleScript or Automator? I’ve tried looking at the documentation and some simple scripting examples, but I’ve never done anything this complicated before and am completely out of my depth, so don’t even know where to start.

MacBook, macOS Sierra (10.12.2)

Posted on Jan 21, 2017 9:38 PM

Reply
11 replies

Jan 22, 2017 1:35 AM in response to beastom

Hi beastom,

I an no expert in AppleScript, but it will help the AppleScript Gurus in this forum if you post a Screen Shot of a small part of your database table. Remove or hide personal information first. Click on the table to show the Row and Column labels. Command shift 4 and drag (not command shift 3 for the whole screen; that is often difficult to read).


See this User Tip by Wayne on how to post a screen shot.

How to Post a screenshot to the Apple Discussion Forums


Regards,

Ian.

Jan 22, 2017 4:24 PM in response to Yellowbox

Here is a shot with the pop up menu selected to show the values. The SN value is used for vlookup to populate the values in the other cells.

User uploaded file

Below is an example with 1101 “Fred” selected. Everything save the header column on the left is populated via vlookup using the SN value.

User uploaded file

This works fine for manually stepping through to view individual grade reports. What I would like to do is to step through the students one by one programmatically, and generate a PDF page for each student from this sheet. While I could do this by hand, it would take a *very* long time as, like I said, I have about 500 total students in 6 different grades that I would like to generate reports for.

Jan 23, 2017 6:13 AM in response to beastom

Hi beastom,


The big difficulty in doing what you want is that AppleScript does not have access to the "save as PDF" menu in the print dialogue. "Export to PDF" will only export the entire file. There are workarounds possible.


Are your SN values continuous? i.e. 1101 thru approx. 1601 without gaps? Is there a master list of student's SNs?


quinn

Jan 23, 2017 4:11 PM in response to t quinn

No, they are not continuous for all students, however within the grade (the first grade middle school class shown in my screenshots, for example) the numbers are continuous. In other words, I have a grade table with all of the students in that grade in the same table, and I use the student number (SN) as the key for each table. The vlookup works on two tables: the grade table, and a separate points table that lists assignments, point values, and percentage multipliers.


I have each sheet broken down by grade because I have to export the grade table regularly and they expect to have only the information for that grade. Also, each grade’s points, assignments, and percentages are calculated separately. It would be infeasible to have one master table with everything from 5 grade levels. Given that sometimes the progress between different classes is variable, I really ought to split the tables further than I do, but since I’m already pushing the “database” aspects of Numbers further than it ought to go, I haven’t fragmented it further.


If you’re asking how much I’m willing to deal with running/modifying a script to get all the work done, I’m okay with having to prepare separate scripts for each grade. I’m not expecting to be able to put together a Swiss Army knife script that deals with pulling data from anywhere and everywhere.


I’m also not married to an AppleScript solution. I’m looking at things like Keyboard Maestro to see if I can string together a macro that will accomplish pretty much the same outcome.


Thanks for taking the time to look at this problem, by the way.

Jan 23, 2017 6:04 PM in response to beastom

Hi, I've followed this thread with interest. I (reluctantly) conclude that Numbers, together with AppleScript, is not the best toolbox for producing 500 reports in pdf form. For that sort of task you will do much better with a "true" database program such as FileMaker. It's possible that the database portion of the LibreOffice or other open source office suite could also do this.


SG

Jan 25, 2017 6:16 PM in response to t quinn

Okay, related workaround problem: how would I programmatically step through changing the value of that pop up menu in the cell?


I think that I could kludge this by writing a script to copy all the tables on the sheet to a new Numbers doc, add a sheet, copy, repeat, and then just print/export the newly created file at the end. Since I’m doing a grade at a time, I shouldn’t have more than 80–100 students, which hopefully won’t hit any limits with Numbers regarding the number of sheets in a file.

Jan 25, 2017 7:11 PM in response to beastom

beastom wrote:


kludge this by writing a script to copy all the tables on the sheet to a new Numbers doc, add a sheet, copy, repeat, and then just print/export the newly created file at the end.


While this is theoretically possible, Numbers really isn't the right tool for the kind of job you are describing. Numbers is a nifty spreadsheet for calculations, but you are in essence looking for the "report writing" function of a database app. Check out the database modules of the free clone Office suites, or, if you have the budget, FileMaker.


SG

Jan 27, 2017 6:31 AM in response to SGIII

I understand that I’m pushing the capabilities of Numbers. The reasons I am pursuing this idea still are:


1) These are the tools I have. Learning about AppleScript or similar scripting tools to do this will probably pay dividends later. Common programmer advice is to find a problem you have, and learn enough to solve it.

2) Time put into learning how to use a different office suite is probably wasted time. I’d have to re-implement everything I’ve already done through iterations over months (in some cases years) in a different software suite that I would — in all likelihood — never use for anything else. It’s never as easy as just importing your existing tables. I’ve tried using things like Open Office in the past. I was never able to get anything that should, in theory, work to actually work properly; and that was just printing mailing labels.

3) Given that case 2 looks like a time sink, I might just as well try to learn MySQL or R … except that I don’t really have the time or attention to spare to learn something that in-depth, which is why I’m trying to find some way of automating what I have, so that I have the time and attention to spare for more ambitious projects.


Regardless, posting here is time I’m not doing something productive, so I should probably cut my losses. If I do figure out a workable solution, I’ll post it later.

Jan 27, 2017 6:46 AM in response to beastom

beastom wrote:


I might just as well try to learn MySQL or R …


How about, instead, looking into to learning about databases with "report writer" modules? You're not trying to construct a relational database here, or do sophisticated statistical reports and graphs. You're trying to spit out reports (hundreds of them in fact) based (presumably) on fairly simple underlying data and calculations. If you have MS Office on Windows, then Access is good at that kind of thing. On the Mac, FileMaker will do the job. And there are also the database modules of the free office clones that can produce reports.


SG

Jan 27, 2017 4:47 PM in response to SGIII

I’m not trying to argue that my approach is right, but the reality of my situation is that I can’t throw money at the problem. I’m doing this for work, but there is zero chance I’ll get money for software since I am literally the only Mac user, and the information I’m trying to track is solely my responsibility. All they care about are the final grades, and their systems are set up only to deal with that information.


I want to generate the reports in order to be more organized and granular on my end, and to provide decent feedback to students. I’ve been given more and more responsibilities over time to the point where doing things by hand has gotten ridiculous, but I can’t realistically afford the time and monetary investment to start over from scratch. Cross-applying the things I can learn from automation will (hopefully) also help with other little things I do daily.


Yes, spending a week or more of necessarily fragmented time (and several day’s pay) on setting up FileMaker Pro would probably solve this particular problem, but it wouldn’t do anything beyond that. I do also have other responsibilities where a relational database would probably be appropriate, so maybe I really should find a way to learn enough about heavy-duty databases to handle those things too.


I wasn’t being entirely facetious earlier about learning MySQL or R. If I can ever make that investment, the personal benefit would be having that knowledge and expertise, and the practical benefit would be being able to deploy a platform-agnostic system that others could use. The problem is that I don’t see realistically being able to do that anytime soon.


Anyway, no one needs to read a longer litany of my woes.

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.

Generating reports with Numbers

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