-->
Exporting DocumentsExporting Numbers documents is done using the export command from the Numbers Suite .
export v : Export a presentation to another file(s).
export document : The presentation to export.
to ( file ) : A reference to the file (folder) to be created. When exporting images or HTML, a new folder, containing the exported items, is created instead of a file.
as ( PDF / Microsoft Excel / CSV / Numbers 09 ) : The format in which the document is to be exported.
[ with properties ( export options ) ] : An AppleScript record containing property:value pairings for the initial values for properties of the exported object.
export options n : The export options for the Numbers export command.
exclude summary worksheet ( boolean ) : (Numbers 3.6) Whether to exclude a summary worksheet in Excel workbook.
image quality ( good / better / best ) : (Numbers 3.6) The quality of the images in the exported PDF file.
password ( text ) : The password to use when the exported PDF is encrypted.
password hint ( text ) : The password hint.
NOTE: The Numbers version 3.6 scripting dictionary includes enhanced export options for exporting to Excel format, as well as image compression options for images placed within the exported document.
Export ScriptsThe following are script examples for each of the export types:
This script exports the frontmost Numbers presentation to a PDF file. Set the boolean value of the useEncryptionDefaultValue property to either true or false to determine whether you will be prompted for the password to use in encrypting the PDF file.
Export to PDF | ||
Open in AppleScript Editor | ||
01 | property exportFileExtension : "pdf" | |
02 | property useEncryptionDefaultValue : true | |
03 | ||
04 | -- THE DESTINATION FOLDER | |
05 | -- (see the "path" to command in the Standard Additions dictionary for other locations, such as movies folder, pictures folder, desktop folder) | |
06 | set the defaultDestinationFolder to ( path to documents folder ) | |
07 | ||
08 | set usePDFEncryption to useEncryptionDefaultValue | |
09 | tell application "Numbers" | |
10 | activate | |
11 | try | |
12 | if not ( exists document 1) then error number -128 | |
13 | ||
14 | if usePDFEncryption is true then | |
15 | -- PROMPT FOR PASSWORD (OPTIONAL) | |
16 | repeat | |
17 | display dialog "Enter a password for the PDF file :" default answer ¬ | |
18 | "" buttons ¬ | |
19 | default button 3 with hidden answer | |
20 | copy the result to ¬ | |
21 | ||
22 | if buttonPressed is "No Password" then | |
23 | set usePDFEncryption to false | |
24 | exit repeat | |
25 | else | |
26 | display dialog "Enter the password again:" default answer ¬ | |
27 | "" buttons ¬ | |
28 | default button 3 with hidden answer | |
29 | copy the result to ¬ | |
30 | ||
31 | if buttonPressed is "No Password" then | |
32 | set usePDFEncryption to false | |
33 | exit repeat | |
34 | else | |
35 | if firstPassword is not secondPassword then | |
36 | display dialog "Passwords do no match." buttons ¬ | |
37 | Try Again"> default button 2 | |
38 | else | |
39 | set providedPassword to the firstPassword | |
40 | set usePDFEncryption to true | |
41 | exit repeat | |
42 | end if | |
43 | end if | |
44 | end if | |
45 | end repeat | |
46 | end if | |
47 | ||
48 | -- DERIVE NAME AND FILE PATH FOR NEW EXPORT FILE | |
49 | set documentName to the name of the front document | |
50 | if documentName ends with ".numbers" then ¬ | |
51 | set documentName to text 1 thru -9 of documentName | |
52 | ||
53 | tell application "Finder" | |
54 | set exportItemFileName to documentName & "." & exportFileExtension | |
55 | set incrementIndex to 1 | |
56 | repeat until not (exists document file exportItemFileName of defaultDestinationFolder ) | |
57 | set exportItemFileName to ¬ | |
58 | documentName & "-" & ( incrementIndex as string ) & "." & exportFileExtension | |
59 | set incrementIndex to incrementIndex + 1 | |
60 | end repeat | |
61 | end tell | |
62 | set the targetFileHFSpath to ( defaultDestinationFolder as string ) & exportItemFileName | |
63 | ||
64 | -- EXPORT THE DOCUMENT | |
65 | with timeout of 1200 seconds | |
66 | if usePDFEncryption is true then | |
67 | export front document to file targetFileHFSpath ¬ | |
68 | as PDF with properties | |
69 | else | |
70 | export front document to file targetFileHFSpath as PDF | |
71 | end if | |
72 | end timeout | |
73 | ||
74 | on error errorMessage number errorNumber | |
75 | if errorNumber is not -128 then | |
76 | display alert "EXPORT PROBLEM" message errorMessage | |
77 | end if | |
78 | error number -128 | |
79 | end try | |
80 | end tell | |
81 | ||
82 | -- SHOW THE NEW PDF FILE | |
83 | tell application "Finder" | |
84 | activate | |
85 | reveal document file targetFileHFSpath | |
86 | end tell |
This script exports the frontmost Numbers presentation to one or more CSV files.
Export to CSV | ||
Open in AppleScript Editor | ||
01 | property exportFileExtension : "csv" | |
02 | ||
03 | -- THE DESTINATION FOLDER | |
04 | -- (see the "path to" command in the Standard Additions dictionary for other locations, such as movies folder, pictures folder, desktop folder) | |
05 | set the defaultDestinationFolder to ( path to documents folder ) | |
06 | ||
07 | tell application "Numbers" | |
08 | activate | |
09 | try | |
10 | if not ( exists document 1) then error number -128 | |
11 | ||
12 | tell the front document | |
13 | set documentName to its name | |
14 | if documentName ends with ".numbers" then ¬ | |
15 | set documentName to text 1 thru -9 of documentName | |
16 | set tableCount to the count of every table of every sheet | |
17 | end tell | |
18 | ||
19 | -- a DOCUMENT WITH ONE TABLE WILL EXPORT TO A FILE | |
20 | if tableCount is 0 then | |
21 | tell application "Finder" | |
22 | set newExportItemName to documentName & "." & exportFileExtension | |
23 | set incrementIndex to 1 | |
24 | repeat until not ( exists document file newExportItemName of defaultDestinationFolder ) | |
25 | set newExportItemName to ¬ | |
26 | documentName & "-" & ( incrementIndex as string ) & "." & exportFileExtension | |
27 | set incrementIndex to incrementIndex + 1 | |
28 | end repeat | |
29 | end tell | |
30 | set the targetFileHFSpath to ¬ | |
31 | ( defaultDestinationFolder as string ) & newExportItemName | |
32 | ||
33 | -- EXPORT THE DOCUMENT | |
34 | with timeout of 1200 seconds | |
35 | export front document to file targetFileHFSpath as CSV | |
36 | end timeout | |
37 | ||
38 | set exportedItempath to targetFileHFSpath | |
39 | else | |
40 | -- a DOCUMENT CONTAINING MULTIPLE TABLES WILL EXPORT TO A FOLDER | |
41 | tell application "Finder" | |
42 | set newFolderName to documentName | |
43 | set incrementIndex to 1 | |
44 | repeat until not ( exists folder newFolderName of defaultDestinationFolder ) | |
45 | set newFolderName to documentName & "-" & ( incrementIndex as string ) | |
46 | set incrementIndex to incrementIndex + 1 | |
47 | end repeat | |
48 | set targetHFSpath to ( defaultDestinationFolder as string ) & ¬ | |
49 | newFolderName & "." & exportFileExtension | |
50 | end tell | |
51 | ||
52 | -- EXPORT THE DOCUMENT | |
53 | with timeout of 1200 seconds | |
54 | export front document as CSV to file targetHFSpath | |
55 | end timeout | |
56 | ||
57 | set exportedItempath to ¬ | |
58 | ( defaultDestinationFolder as string ) & newFolderName & ":" | |
59 | end if | |
60 | ||
61 | on error errorMessage number errorNumber | |
62 | if errorNumber is not -128 then | |
63 | display alert "EXPORT PROBLEM" message errorMessage | |
64 | end if | |
65 | error number -128 | |
66 | end try | |
67 | end tell | |
68 | ||
69 | -- SHOW THE NEW EXPORTED ITEM | |
70 | tell application "Finder" | |
71 | activate | |
72 | reveal item exportedItempath | |
73 | end tell |
Export to Microsoft Excel
This script exports the frontmost Numbers presentation to a Microsoft Excel file.
Export to Numbers 2009
This script exports the frontmost Numbers presentation to a Numbers 2009 file.
IMPORTANT TIP: Learn how to save and run your favorite scripts using the system-wide Script Menu.