Hi everybody,
I am currently working on a script which creates fancy reports for a client by filling Numbers templates with data from our database.
Both the filling of a document and the exporting in PDF format work great, but I have a problem with Number’s way of updating the graphs on the sheets of a document.
It seems to me that Numbers does not update all graphs before creating the PDF representation of the document. And so I encounter PDFs where the graphs still look like as in the original template.
To avoid this nasty problem, my current script workflow is as follows:
- Open template
- Fill template with data
- Save template to new file
- Close template
- Open newly created file
(now Numbers updates all graphs)
- Save as PDF
- Close document
Doing so, it works just fine, nevertheless it doesn’t feel right to reopen every created documemt in order to update all the graphs in it…
Does anybody have a better idea?
Thanks in advance and best regards from sunny and (quite) warm Berlin,
Martin
With “graph” you mean “chart” right? In that case it’s strange then your document doesn’t update your charts, because when I change a value of a cell like this:
tell application "Numbers" to set value of cell "B2" of table 1 of sheet 1 of document 1 to 100000
it automatically updates my chart.
Hi ief2,
Thanks for taking the time to test it. Yes, by graph I mean chart.
Are the chart and the corresponding table are located on the same sheet in your test environment?
I am still having problems when the table and the chart are on different sheets, nevertheless my workaround works…
Best regards from rainy Berlin,
Martin
Well, after trying out, I also noticed the charts didn’t get updated when they are on another, not shown sheet, as you said. So I thought of activating it by clicking the row in the table view. I came up with this code:
set myPath to (path to desktop as text) & "test.pdf"
try
do shell script "mkfile 10b " & quoted form of POSIX path of myPath
end try
tell application "Numbers"
tell document 1 to tell sheet 1 to tell table 1 to set value of cell "F2" to 0
tell application "System Events" to tell process "Numbers" to select row 4 of outline 1 of scroll area 1 of splitter group 1 of splitter group 1 of window "Naamloos" -- the reference to the row in the table view
delay 1 -- time to select and update (just inserted it to be sure)
save document 1 in (myPath as alias)
end telll
You’ll have to of course set up a different row number (UI Browser says the raws haven’t got a name) to select the right object.
Hope it works,
ief2