Save sheet as a .prn, or a space delimited file
Thanks in advance!!!!
iMac intel, Mac OS X (10.5.2)
iMac intel, Mac OS X (10.5.2)
jjmancini wrote:
I need to be able to save my numbers file as a prn file, which I also believe to be a space delimited file. Does anyone know how i can do this?
The PRN file type is primarily associated with 'Printer Text File'. When you print to a file the program outputs whatever it would have sent to the printer you have attached to your computer to a file instead. The idea is that later you might want to send this file to a similar printer on a different computer. So, the main use for a .PRN file is to copy it to a printer in order to get the output. You can open a .PRN file in any text editor but what you'll likely see is your text surrounded by a whole bunch of "junk" which represents all the various printer codes necessary to set margins, special spacing, graphics, etc., etc
jjmancini wrote:
All it really is, is a space delimited file. Thus it translates column distance as spaces.
--[SCRIPT columnsBySpaces]
(*
Enregistrer le script en tant que Script : columnsBySpaces.scpt
déplacer le fichier ainsi créé dans le dossier
<VolumeDeDémarrage>:Users:<votreCompte>:Library:Scripts:Applications:Numbers:
Il vous faudra peut-être créer le dossier Numbers et peut-être même le dossier Applications.
Dans la ligne d'en-têtes la plus haute, indiquer les largeurs de colonnes (en nombre caractères)
En l'absence de valeurs numérique, le script utilisera une largeur de 12 caractères.
Sélectionner les cellules à exporter
menu Scripts > Numbers > columnsBySpaces
Un fichier nommé "columnsBySpaces_aaaammjj-hhmmss.txt" sera créé sur le bureau.
Vous pourrez l'imprimer en utilisant une police de chasse constante.
--=====
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 a Script: columnsBySpaces.scpt
Move the newly created file into the folder:
<startup Volume>:Users:<yourAccount>:Library:Scripts:Applications:Numbers:
Maybe you would have to create the folder Numbers and even the folder Applications by yourself.
In the higher header row, enter the wanted widths of columns (characters numbers).
If there is no numerical value, the script use 12 characters by column.
menu Scripts > Numbers > columnsBySpaces
A file named "columnsBySpaces_aaaammjj-hhmmss.txt" will be created on the Desktop.
You will be able to print it using a monospaced font.
--=====
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.
Save this script as a … Script in the "Folder Actions Scripts" folder
<startupVolume>:Library:Scripts:Folder Action Scripts:
--=====
Yvan KOENIG (VALLAURIS, France)
2010/04/29
*)
--=====
on run
set |largeurParDéfaut| to 12
my activateGUIscripting()
set {dName, sName, tName, rName, rowNum1, colNum1, rowNum2, colNum2} to my getSelParams()
tell application "Numbers" to tell document dName to tell sheet sName to tell table tName
set lesLargeurs to {}
tell row 1
repeat with c from colNum1 to colNum2
try
set largeur to (value of cell c) as integer
if largeur = 0 then set largeur to |largeurParDéfaut|
on error
set largeur to |largeurParDéfaut|
end try
copy largeur to end of lesLargeurs
end repeat
end tell -- row 1
set lesLignes to {}
repeat with r from rowNum1 to rowNum2
tell row r
set uneLigne to {}
repeat with c from colNum1 to colNum2
set maybe to (value of cell c) as text
set largeur to item c of lesLargeurs
if (count of maybe) < largeur then
repeat until (count of maybe) = largeur
set maybe to maybe & space
end repeat -- until…
end if
copy maybe to end of uneLigne
end repeat -- c
copy my recolle(uneLigne, "") to end of lesLignes
end tell
end repeat -- r
set lesLignes to my recolle(lesLignes, return)
end tell
set nomDuRapport to "columnsBySpaces" & (do shell script "date " & quote & "+_%Y%m%d-%H%M%S" & quote) & ".txt"
set p2d to path to desktop
set p2r to (p2d as Unicode text) & nomDuRapport
tell application "System Events"
if exists (file p2r) then delete (file p2r)
make new file at end of p2d with properties {name:nomDuRapport}
end tell
write lesLignes to (p2r as alias)
end run
--=====
(*
set { dName, sName, tName, rname, rowNum1, colNum1, rowNum2, colNum2} to my getSelParams()
*)
on getSelParams()
local r_Name, t_Name, s_Name, d_Name, col_Num1, row_Num1, col_Num2, row_Num2
set {d_Name, s_Name, t_Name, r_Name} to my getSelection()
if r_Name is missing value then
if my parleAnglais() then
error "No selected cells"
else
error "Il n'y a pas de cellule sélectionnée !"
end if
end if
set two_Names to my decoupe(r_Name, ":")
set {row_Num1, col_Num1} to my decipher(item 1 of two_Names, d_Name, s_Name, t_Name)
if item 2 of two_Names = item 1 of two_Names then
set {row_Num2, col_Num2} to {row_Num1, col_Num1}
else
set {row_Num2, col_Num2} to my decipher(item 2 of two_Names, d_Name, s_Name, t_Name)
end if
return {d_Name, s_Name, t_Name, r_Name, row_Num1, col_Num1, row_Num2, col_Num2}
end getSelParams
--=====
(*
set {rowNumber, columnNumber} to my decipher(cellRef,docName,sheetName,tableName)
apply to named row or named column !
*)
on decipher(n, d, s, t)
tell application "Numbers" to tell document d to tell sheet s to tell table t to return {address of row of cell n, address of column of cell n}
end decipher
--=====
(*
set { d_Name, s_Name, t_Name, r_Name} to my getSelection()
*)
on getSelection()
local _, theRange, theTable, theSheet, theDoc, errMsg, errNum
tell application "Numbers" to tell document 1
repeat with i from 1 to the count of sheets
tell sheet i
set x to the count of tables
if x > 0 then
repeat with y from 1 to x
try
(selection range of table y) as text
on error errMsg number errNum
set {_, theRange, _, theTable, _, theSheet, _, theDoc} to my decoupe(errMsg, quote)
return {theDoc, theSheet, theTable, theRange}
end try
end repeat -- y
end if -- x>0
end tell -- sheet
end repeat -- i
end tell -- document
return {missing value, missing value, missing value, missing value}
end getSelection
--=====
on parleAnglais()
local z
try
tell application "Numbers" to set z to localized string "Cancel"
on error
set z to "Cancel"
end try
return (z is not "Annuler")
end parleAnglais
--=====
on decoupe(t, d)
local l
set AppleScript's text item delimiters to d
set l to text items of t
set AppleScript's text item delimiters to ""
return l
end decoupe
--=====
on recolle(l, d)
local t
set AppleScript's text item delimiters to d
set t to l as text
set AppleScript's text item delimiters to ""
return t
end recolle
--=====
(*
replaces every occurences of d1 by d2 in the text t
*)
on remplace(t, d1, d2)
local l
set AppleScript's text item delimiters to d1
set l to text items of t
set AppleScript's text item delimiters to d2
set t to l as text
set AppleScript's text item delimiters to ""
return t
end remplace
--=====
(*
removes every occurences of d in text t
*)
on supprime(t, d)
local l
set AppleScript's text item delimiters to d
set l to text items of t
set AppleScript's text item delimiters to ""
return (l as text)
end supprime
--=====
on activateGUIscripting()
tell application "System Events"
if not (UI elements enabled) then set (UI elements enabled) to true (* to be sure than GUI scripting will be active *)
end tell
end activateGUIscripting
--=====
(*
==== Uses GUIscripting ====
*)
(*
This handler may be used to 'type' text, invisible characters if the third parameter is an empty string.
It may be used to 'type' keyboard shortcuts if the third parameter describe the required modifier keys.
*)
on shortcut(a, t, d)
local k
tell application a to activate
tell application "System Events" to tell application process a
set frontmost to true
try
t * 1
if d is "" then
key code t
else if d is "c" then
key code t using {command down}
else if d is "a" then
key code t using {option down}
else if d is "k" then
key code t using {control down}
else if d is "s" then
key code t using {shift down}
else if d is in {"ac", "ca"} then
key code t using {command down, option down}
else if d is in {"as", "sa"} then
key code t using {shift down, option down}
else if d is in {"sc", "cs"} then
key code t using {command down, shift down}
else if d is in {"kc", "ck"} then
key code t using {command down, control down}
else if d is in {"ks", "sk"} then
key code t using {shift down, control down}
else if (d contains "c") and (d contains "s") and d contains "k" then
key code t using {command down, shift down, control down}
else if (d contains "c") and (d contains "s") and d contains "a" then
key code t using {command down, shift down, option down}
end if
on error
repeat with k in t
if d is "" then
keystroke (k as text)
else if d is "c" then
keystroke (k as text) using {command down}
else if d is "a" then
keystroke k using {option down}
else if d is "k" then
keystroke (k as text) using {control down}
else if d is "s" then
keystroke k using {shift down}
else if d is in {"ac", "ca"} then
keystroke (k as text) using {command down, option down}
else if d is in {"as", "sa"} then
keystroke (k as text) using {shift down, option down}
else if d is in {"sc", "cs"} then
keystroke (k as text) using {command down, shift down}
else if d is in {"kc", "ck"} then
keystroke (k as text) using {command down, control down}
else if d is in {"ks", "sk"} then
keystroke (k as text) using {shift down, control down}
else if (d contains "c") and (d contains "s") and d contains "k" then
keystroke (k as text) using {command down, shift down, control down}
else if (d contains "c") and (d contains "s") and d contains "a" then
keystroke (k as text) using {command down, shift down, option down}
end if
end repeat
end try
end tell
end shortcut
--=====
--[/SCRIPT]
--
Badunit wrote:
Got the file. I have three suggestions.
1) For the formatting of the "price" column to come through as 0.000 versus 0.0, it must be formatted as text just like the "change" column. I don't know if AppleScript is able to tell the complete formatting of a cell. A cell formatted as a number with four decimal places ends up having the extraneous zeros removed so 0.0000 turns into 0.0. As text, all decimal places are retained. Plus you will need to do this for #3 to work as I wrote it.
2) In Yvans script, nine lines after Run, replace +*set largeur to (value of cell c) as integer*+ with +*set largeur to (width of column c) / 5 as integer*+ . This sets the column width but it does not take font size into account. Dividing by five looked good to me but you may want to adjust the divisor.
3) In Yvan's script, right after +*set maybe to (value of cell c) as text*+ add the line +*if maybe = "0.0" then set maybe to ""*+ . Blank cells get turned into 0.0 by the script and I don't know of a robust way to tell a blank cell 0.0 from a real 0.0. This gets rid of the extraneous 0.0's but if you have a real 0.0 that you want to keep, it will be gone too.
This is not a perfect solution and is really designed for your particular document.
repeat with c from colNum1 to colNum2
set maybe to (value of cell c) as text
if maybe is in {"", "0.0", "0,0"} then set maybe to "" -- ADDED
set largeur to item c of lesLargeurs
--
Save sheet as a .prn, or a space delimited file