set mondoc to "monfichier"
set chemin to ((path to home folder) & "downloads:" & mondoc & ".csv") as string
set chemin to chemin as alias
tell application "Numbers"
activate
open chemin
activate
set chemin to ((path to home folder) & "downloads:" & "export.csv") as string
export front document to file chemin as CSV --with properties "CSV"
close front document
end tell
set mondoc to "export"
set chemin to ((path to home folder) & "downloads:" & mondoc & ".csv") as string
set chemin to chemin as alias
--créer une nouvelle feuille
tell application "Numbers"
activate
open chemin
tell document mondoc
make new sheet
tell active sheet
delete every table
set thesheet to make new table with properties {row count:2, column count:8}
end tell
end tell
tell the first table of sheet 2 of document mondoc
remove column 1
remove row 1
end tell
-- copier les titres de colonnes
set colonne to {"A", "B", "C", "D", "E", "F", "G"}
repeat with i from 1 to 7
set lacolonne to item i of colonne
tell the first table of sheet 1 of document mondoc
set titre to value of cell (lacolonne & "7")
end tell
tell the first table of sheet 2 of document mondoc
set value of cell (lacolonne & "1") to titre
end tell
end repeat
end tell
set laligne to 8
set laligneplus to 8
set laligneB to 2
tell application "Numbers"
activate
tell the first table of sheet 1 of document mondoc
set nbligne to count row
end tell
end tell
-- Concatenner et copier les mouvements
tell application "Numbers"
activate
repeat
if laligne > nbligne then exit repeat
tell the first table of sheet 1 of document mondoc
set ladate to value of cell ("A" & laligne)
set nature to value of cell ("B" & laligne)
repeat
set laligneplus to laligneplus + 1
if laligneplus > nbligne then exit repeat
set x to value of cell ("A" & laligneplus)
if x is missing value then
set nature to nature & " " & value of cell ("B" & laligneplus)
else
exit repeat
end if
end repeat
set debit to value of cell ("c" & laligne)
set credit to value of cell ("D" & laligne)
set devise to value of cell ("E" & laligne)
set datevaleur to value of cell ("F" & laligne)
set libelle to value of cell ("G" & laligne)
end tell
tell the first table of sheet 2 of document mondoc
add row below last row
set value of cell ("A" & laligneB) to ladate
set value of cell ("B" & laligneB) to nature
set value of cell ("C" & laligneB) to debit
set value of cell ("D" & laligneB) to credit
set value of cell ("E" & laligneB) to devise
set value of cell ("F" & laligneB) to datevaleur
set value of cell ("G" & laligneB) to libelle
end tell
set laligneB to laligneB + 1
set laligne to laligneplus
end repeat
tell the first table of sheet 2 of document mondoc
set the selection range to column "C"
set format of selection range to currency
set the selection range to column "D"
set format of selection range to currency
set the selection range to column "A"
set format of selection range to date and time
set the selection range to column "F"
set format of selection range to date and time
end tell
end tell