SCRIPT NUMBERS TO DELETE COLUMNS AND ROWS

Hi everybody,
I would to know if it is possible to script Numbers09 to delete specific rows and columns. Here is my problem.
I have a log generated by a printer. The log is a Tab Text based. I can open it within Numbers. I see a table well formated, but I have 4 rows and 6 columns that are redundant (Row 1,2,3,4, column C,D,E,J,K,L)> Do you think it's possible to AppleScipt Numbers09 to do that.

Oh yes I forgot, I need the file to be exported as CSV Format (Unicode).

Any help will be really appreciated

3.2GHz Quad-Core, Mac OS X (10.5.6)

Posted on Mar 10, 2009 9:16 AM

Reply
5 replies

Mar 10, 2009 10:52 AM in response to mactoubib

(1) No need to shout, more of us are not deaf !

(2) I don't understand.
Why is a script required to do that ?
To remove columns CDE select their tabs then delete them
To remove columns JKL select their tabs then delete them
To remove rows 1, 2, 3, 4 select their tabs then delete them

The feature is described in the Help and in the User Guide (page 57).

If you want to remove these columns and rows from a text file, the use of Number is not required.

To do the trick in Numbers you may use:


tell application "Numbers" to tell document 1

tell sheet 1 to tell table 1

repeat with r in {4, 3, 2, 1}
remove row r
end repeat

repeat with n in {11, 10, 9, 5, 4, 3}
remove column n
end repeat

end tell
end tell


CAUTION, you must list the items to remove backwards.

Yvan KOENIG (from FRANCE mardi 10 mars 2009 18:52:24)

Mar 10, 2009 2:47 PM in response to KOENIG Yvan

Bonjour Yvan,

Merci beaucoup pour le script et désolé pour les majuscules, je n'ai pas fait attention. Le fichier en question est généré par une imprimante et il faut le faire 2 fois par jour d'où l'idée de scripter. Vous prétendez que c'est possible de le faire sans passer par Numbers, directement sur le fichier Text. Je serai curieux de voir la chose.

PS : En passant, c'est vrai que la plupart ne sont pas sourds, mais moi je le suis (à 70%) sans farce. Je ne m'en porte pas plus mal, il y a des côtés pratiques à l'handicap dans certaines situations

Mar 10, 2009 3:16 PM in response to mactoubib

mactoubib wrote:
Bonjour Yvan,

Merci beaucoup pour le script et désolé pour les majuscules, je n'ai pas fait attention. Le fichier en question est généré par une imprimante et il faut le faire 2 fois par jour d'où l'idée de scripter. Vous prétendez que c'est possible de le faire sans passer par Numbers, directement sur le fichier Text. Je serai curieux de voir la chose.


Je verrais cela demain. Pour moi c'est l'heure de débrancher.

ça commencera par quelquechose comme:


set fichier to (path to desktop as text) & "essai.txt"
set lesLignes to paragraphs of (read file fichier from 1)
set lesLignes to items 5 thru -1 of lesLignes

avec ça, les lignes 1 à 4 seraient déjà supprimées 😉

Avant cela voici une variante peut -être plus facile à utiliser.


tell application "Numbers" to tell document 1

tell sheet 1 to tell table 1
set theRows to {1, 2, 3, 4}
repeat with i from (count of theRows) to 1 by -1
remove row (item i of theRows)
end repeat

set theColumns to {"C", "D", "E", "I", "J", "K"}
repeat with i from (count of theColumns) to 1 by -1
remove column (item i of theColumns)
end repeat

end tell
end tell


Cette fois, les colonnes sont désignées par leur "nom" et plus par leur index.
Les listes sont dans l'ordre croissant mais le script les balaie à reculons.

La question sur l'écriture en CSV concerne-t-elle le cas Numbers ou le cas sans Numbers.

Il me serait utile de disposer d'un fichier échantillon pour les essais requis.

Cliquez mon nom (en bleu) pour avoir mon adresse.

Yvan KOENIG (from FRANCE mardi 10 mars 2009 23:09:45)

Mar 11, 2009 3:25 AM in response to KOENIG Yvan

Here is the complete script

--[SCRIPT]

(*
Yvan KOENIG (Vallauris, FRANCE)
11 mars 2009
*)
property |lignesÀsupprimer| : {1, 2, 3, 4}
property |colonnesÀsupprimer| : {4, 5, 6, 22, 23, 24}
property lesLignes : {}
property |filtré| : {}
property ligneI : {}
property |ligneIFiltrée| : {}
--=====
on run
my nettoie()
(* Define delim to behave as Numbers do *)
if character 2 of (0.5 as text) is "," then
set delim to ";"
else
set delim to ","
end if

set p2d to path to desktop as text
set source to p2d & "FichierRequis:01.ORIGINAL_FILE.txt"

set my lesLignes to paragraphs of (read file source from 1)

repeat with i from 1 to count of my lesLignes
if i is not in my |lignesÀsupprimer| then
set my ligneI to my decoupe(item i of my lesLignes, tab)
set my |ligneIFiltrée| to {}
repeat with j from 1 to count of my ligneI
if j is not in my |colonnesÀsupprimer| then
set itemJ to item j of my ligneI
if j = 5 then
set itemJ to quote & my (recolle(my decoupe(itemJ, ","), space)) & quote (* la date *)
else if itemJ contains delim then
set itemJ to quote & itemJ & quote
end if
copy itemJ to end of my |ligneIFiltrée|
end if -- j is not …
end repeat -- j
copy my recolle(|ligneIFiltrée|, delim) to end of my |filtré|
end if -- i is not …
end repeat -- i
set |filtré| to my recolle(my |filtré|, return)

set nomDuFichier to "02MODIFIEDFILE"
set destination to p2d (* you may change it to fit your needs *)
set fichierDest to destination & nomDuFichier
tell application "Finder"
if exists file (fichierDest & ".txt") then delete file (fichierDest & ".txt")
if exists file (fichierDest & ".csv") then delete file (fichierDest & ".csv")
set fichierTxt to (make new file at folder destination with properties {name:nomDuFichier & ".txt"}) as alias
write |filtré| to fichierTxt starting at 1
set name of fichierTxt to (nomDuFichier & ".csv")
end tell
my nettoie()
end run
--=====
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
--=====
on nettoie()
set lesLignes to {}
set |filtré| to {}
set ligneI to {}
set |ligneIFiltrée| to {}
end nettoie
--=====
--[/SCRIPT]


Yvan KOENIG (from FRANCE mercredi 11 mars 2009 11:25:35)

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.

SCRIPT NUMBERS TO DELETE COLUMNS AND ROWS

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