How to print Sequential Numbers like purchase order?

I ma new to mac and Numbers 09 and have a quick question. How do I print sequential numbers? I have my own MS Excel purchase order number with macro and I want to use Iwork Numbers to print the numbers. For example, Purchase Order: 70085-1 is in my form. When I ask to print 20 copies, it will print 70085-1, 70085-1, 70085-3, etc.
Thanks in advance

MacBookPro, Mac OS X (10.6.6)

Posted on Jan 10, 2011 7:35 PM

Reply
8 replies

Jan 10, 2011 8:58 PM in response to FranciSiu

Hi Franci,

Welcome to Apple Discussions and the Numbers'09 forum.

Numbers doesn't support Macros, so that method is out.

Yvan Koenig posted an AppleScript some time ago that incremented invoice numbers, so something similar is likely possible for your POs. As I recall, the script incremented the number either on opening or closing and saving the file, so it required both a close and an open between each invoice.

Are you printing empty PO forms, to be completed on paper (ie. repeated printings of the same document with only the number changed on each), or are there several completed POs on separate pages of the same document?

Details like these, and any others you can supply could help Yvan (or another scripter visiting the forum) to determine if and how this could be done with an AppleScript.

Regards,
Barry

Jan 11, 2011 12:30 AM in response to Barry

Here is a modified version of my original script which was posted in :
http://discussions.apple.com/thread.jspa?messageID=12679002

This time, with a single run, we may define the number of consecutive invoices to create.

--

--[SCRIPT openAndNameInvoiceWithAnumber]
(*
Enregistrer le script en tant que Script : openAndNameInvoiceWithAnumber.scpt
déplacer le fichier créé dans le dossier
<VolumeDeDémarrage>:Utilisateurs:<votreCompte>:Bibliothèque:Scripts:Applications:Pages:
Il vous faudra peut-être créer le dossier Pages et peut-être même le dossier Applications.

aller au menu Scripts , choisir Pages puis choisir openAndNameInvoiceWithAnumber

crée un nouveau document à partir du modèle personnel prédéfini
et renomme le document avec un nouveau numéro.
Il insère également le numéro de facture au début du document.

--=====

L'aide du Finder explique:
L'Utilitaire AppleScript permet d'activer le Menu des scripts :
Ouvrez l'Utilitaire AppleScript situé dans le dossier Applications/AppleScript.
Cochez la case "Afficher le menu des scripts dans la barre de menus".

+++++++

Save the script as Script, Application or Application Bundle: openAndNameInvoiceWithAnumber.xxx

Move the newly created file into the folder:
<startup Volume>:Users:<yourAccount>:Library:Scripts:Applications:Pages:
Maybe you would have to create the folder Pages and even the folder Applications by yourself.

go to the Scripts Menu, choose Pages, then choose openAndNameInvoiceWithAnumber

will create a new document from the defined user template
and name it with a new number.
It also insert the invoice number at the very beginning of the document.

--=====

The Finder's Help explains:
To make the Script menu appear:
Open the AppleScript utility located in Applications/AppleScript.
Select the "Show Script Menu in menu bar" checkbox.

--=====

Yvan KOENIG (Vallauris, FRANCE)
2010/11/30
2010/12/20 edited to apply if the template is a flatfile one.
2011/01/11 added ability to build several invoices in a single call
*)
property theApp : "Pages"
property theExt : ""
property myTemplate : "ma_facture.template" (*
Adapter à vos besoins
Put your preferred template name *)
property fichierNum : "le_numéro.txt" (*
Adapter à vos gouts
Put your preferred text file name *)
--=====
on run

if theApp is "Pages" then
set theExt to "pages"
else
if my parleAnglais() then
error "The application “" & theApp & "” is not supported !"
else
error "L’application « " & theApp & " » n’est pas gérée"
end if
end if
if my parleAnglais() then
set nombredefactures to my askAnumber("Enter the number of consecutive invoices needed", 1, "i")
else
set nombredefactures to my askAnumber("Saisir le nombre de factures consécutives demandé", 1, "i")
end if
repeat nombredefactures times
my buildaninvoice()
end repeat
end run
--=====
on buildaninvoice()
set {p2myTemplate, numero} to my prepare()
set numero to text -5 thru -1 of ("0000" & numero) (* pour numéro de 5 chiffres *)

set UNTITLED_loc to my getLocalizedFrameWorksName(theApp, "Untitled")

tell application "Pages"
activate
try
close document UNTITLED_loc
end try
end tell -- to Pages

tell application "Pages"
activate
open p2myTemplate
set theDoc to numero & "." & theExt
set name of document 1 to theDoc
tell document 1
tell body text
if my parleAnglais() then
set paragraph 1 to "invoice #" & numero & return & paragraph 1
else
set paragraph 1 to "facture n°" & numero & return & paragraph 1
end if
end tell
end tell
end tell
end buildaninvoice
--=====
on getLocalizedFrameWorksName(theApp, x)
local p2bndl
set p2bndl to (path to application support as text) & "iWork '09:Frameworks:SFApplication.framework:Versions:A:Resources:"
set x_loc to my getLocalizedName(theApp, x, p2bndl)
return x_loc
end getLocalizedFrameWorksName
--=====
on getLocalizedFunctionName(theApp, x)
local p2bndl
set p2bndl to (path to application support as text) & "iWork '09:Frameworks:SFTabular.framework:Versions:A:Resources:"
set x_loc to my getLocalizedName(theApp, x, p2bndl)
return x_loc
end getLocalizedFunctionName
--=====
on getLocalizedName(aa, tt, ff)
tell application aa to return localized string tt from table "Localizable" in bundle file ff
end getLocalizedName
--=====
on prepare()
local d1, d2, p2d, containerOfTemplates, pathToTheTemplate, p2n, nn
tell application theApp
set d1 to localized string "Templates" (* nom local du dossier "Modèles" *)
set d2 to localized string "My Templates" (* nom local du dossier "Mes Modèles" *)
end tell -- theApp
set p2d to (path to application support from user domain) as Unicode text
set containerOfTemplates to p2d & "iWork:" & theApp & ":" & d1 & ":" & d2 & ":"
set pathToTheTemplate to containerOfTemplates & myTemplate & ":"
try
set pathToTheTemplate to pathToTheTemplate as alias
on error
if my parleAnglais() then
error "The template “" & pathToTheTemplate & "” is unavailable! Please make sure the template file “" & myTemplate & "” is installed in Numbers “Templates:My Templates” folder, then rerun this script."
else
error "Le modèle « " & pathToTheTemplate & " » est introuvable! Veuillez installer le fichier modèle « " & myTemplate & " » dans le dossier « Modèles:Mes modèles » de Numbers avant de relancer ce script."
end if
end try
tell application "System Events"
if class of disk item (pathToTheTemplate as text) is file then
(* flat file *)
set p2n to containerOfTemplates & fichierNum
if not (exists file p2n) then
make new file at end of folder containerOfTemplates with properties {name:fichierNum}
write "100" to file p2n (* mettez le numéro de départ de votre choix *)
end if -- not…
else
(* package *)
set p2n to "" & pathToTheTemplate & fichierNum
if not (exists file p2n) then
make new file at end of pathToTheTemplate with properties {name:fichierNum}
write "100" to file p2n (* mettez le numéro de départ de votre choix *)
end if -- not…
end if
end tell -- System Events

set nn to read file p2n
set nn to ((nn as integer) + 1) as text
write nn to file p2n starting at 1
return {pathToTheTemplate, nn}
end prepare
--=====
on parleAnglais()
local z
try
tell application theApp to set z to localized string "Cancel"
on error
set z to "Cancel"
end try
return (z is not "Annuler")
end parleAnglais
--=====
(*
Asks for an entry and checks that it is an floating number
set myInteger to my askAnumber(Prompt, DefaultValue, "i")
set myFloating to my askAnumber(Prompt, DefaultValue, "f")
*)
on askAnumber(lPrompt, lDefault, IorF)
local lPrompt, lDefault, n
tell application (path to frontmost application as string)

if IorF is in {"F", "f"} then
set n to text returned of (display dialog lPrompt & " (" & (1.2 as text) & ")" default answer lDefault as text)
try
set n to n as number (* try to convert the value as an number *)
return n
on error
if my parleAnglais() then
display alert "The value needs to be a floating number." & return & "Please try again."
else
display alert "La valeur saisie doit être un nombre décimal." & return & "Veuillez recommencer."
end if
end try
else
set n to text returned of (display dialog lPrompt default answer lDefault as text)
try
set n to n as integer (* try to convert the value as an integer *)
return n
on error
if my parleAnglais() then
display alert "The value needs to be an integer." & return & "Please try again."
else
display alert "La valeur saisie doit être un nombre entier." & return & "Veuillez recommencer."
end if
end try -- 1st attempt
end if -- IorF…
end tell -- application
(*
Here if the first entry was not of the wanted class
second attempt *)
tell application (path to frontmost application as string)
if IorF is in {"F", "f"} then
set n to text returned of (display dialog lPrompt & " (" & (1.2 as text) & ")" default answer lDefault as text)
try
set n to n as number (* try to convert the value as an number *)
return n
on error
--
end try
else
set n to text returned of (display dialog lPrompt default answer lDefault as text)
try
set n to n as integer (* try to convert the value as an integer *)
return n
on error
--
end try -- 1st attempt
end if -- IorF…
end tell -- application

if my parleAnglais() then
error "The value you entered was not numerical !" & return & "Goodbye !"
else
error "La valeur saisie n’est pas numérique !" & return & "Au revoir !"
end if

end askAnumber
--=====
--[/SCRIPT]
--


Yvan KOENIG (VALLAURIS, France) mardi 11 janvier 2011 09:30:37

Jan 12, 2011 5:39 AM in response to jaxjason

jaxjason wrote:
We should be a little clearer on the macro concept. Numbers does not run EXCEL VBA macros, applescript is the equivalent for Apple products. There are a few "Excel Macro to Applescript" guides online that can assist in re-writting your XL macros to Applescript.

I would be glad if what you wrote was true.

Alas it's not.

Macros are triggered by the spreadsheet itself thru dedicated formulas inserted in cells.

This feature is available in AppleWorks where a formula may trigger an AppleScript.
Alas, there isn't such a feature in Numbers. I filed reports to Apple urging them to fill the gap but, at this time, I have no news about that.

As I am optimistic today, I will say : *_"No news = Good News"._*

At this time, it's the user duty to trigger Applescripts designed to drive some Numbers features.

Yvan KOENIG (VALLAURIS, France) mercredi 12 janvier 2011 14:39:19

Jan 12, 2011 9:05 AM in response to jaxjason

I don't use Excel. Given what you wrote, it appear that macros in Excel are not so useful that they where in AppleWorks where we had two ways to trigger them :

buttons as the way which you describe for Excel
formulas using the MACRO() function which was able to trigger macros or AppleScripts.

The macros where dropped when macOs X was delivered but the ability to trigger scripts via formulas is always available and I use it very often.

It's this feature which I am really missing.
I must add that, given the fact that at this time Numbers recalculate everything in a document when we make a simple change, I guess that delivering the MACRO() function will require important changes in the app.

So, what we are missing (based on a comparison with Excel) is :
(1) the ability to link scripts to buttons. At this time we have only the Scripts menu which doesn't make the difference between scripts dedicated to document A and scripts dedicated to application B
(2) a more complete and coherent access to application's features thru AppleScript.
For instance,
the Print support is quite null,
grabbing a formula is complicated,
grabbing the status of cells (merged, hidden…) is impossible,
grabbing/setting a cell format is unavailable (we may set a cell as number or date_time but can't detail these formats)
setting the focus to a given table of a given sheet requires a lot of awful trickery
setting the value of a checkbox requires also some trickery

I don't continue to list every missing features in the scripting area.

Yvan KOENIG (VALLAURIS, France) mercredi 12 janvier 2011 18:05:41

Jan 12, 2011 9:52 AM in response to KOENIG Yvan

Completely agree on your list, and hope that Apple continues to add features avaialable to us.

the macros we write for my firm do just what you say, plus we can adjust the menu to reflect only macros for that document, to create new templates, scrape data from other sources (like main frame screens), etc... It is very easy to create new functionality in excel using macros that can be used in cells.

But even better than using the Macro() command, you can create all new functions that you can call directly like CalculateMyPay() if you wanted to. I hope they add the things you listed and add even more like what I am mentining here too.

If you have any contact that I can write to with my ideas too, Yvan, please feel free to write me outside the forums and let me know where I can submit them.

Thanks, and nice to see you around. I spend alot of time around the ipad forums recently.

Jason

Jan 13, 2011 2:32 AM in response to jaxjason

Nothing secret so I may answer in the forum.

I registered (for free) as a developer so I may file bug reports as well as suggestions in the dedicated Web page (bugreport.apple.com)

In the past I filed reports to someone in Apple France but it appeared that it just added a supplementary level to an already high stack of levels.

I don't know for sure what is more efficient :

(1) file a suggestion thru the developer channel
(2) ask users here to file the suggestion thru the feedback channel.
Numerous request from;different users may push the iWork team to apply the 80% rule.

What I know is that some users asked thru feedback to get windows opening as center in the screen and they got it.
So, I was forced to write a script which trigger the create a document feature and move the window where I want it to be : on the left edge.

Some users asked for several headers, they got them and in the process, we loose a very useful feature :

Applying a Formula Once to Cells in a Column or Row
When a table has header cells, you can use them to quickly apply a formula to all the
cells in a row or column. The values in the cells are recomputed using the formula. This
formula is called a header formula.

Yvan KOENIG (VALLAURIS, France) jeudi 13 janvier 2011 11:32:30

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.

How to print Sequential Numbers like purchase order?

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