IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

AppleScript Discussion :

Pour remplacer un fichier déjà existant sans message


Sujet :

AppleScript

  1. #1
    Membre à l'essai
    Homme Profil pro
    Enseignant
    Inscrit en
    Juillet 2017
    Messages
    17
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 52
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Enseignant
    Secteur : Conseil

    Informations forums :
    Inscription : Juillet 2017
    Messages : 17
    Points : 12
    Points
    12
    Par défaut Pour remplacer un fichier déjà existant sans message
    Bonjour

    Pas trés expert à l'appleScript, je viens vers vous pour un pb surement très simple pour beaucoup d'entre vous.
    Quand je lance ce script, je suis bloqué par excel qui me demande si je veux remplacer mon fichier dans cet emplacement.
    Je ne veux pas de message, je souhaite que mon script remplace le fichier existant sans me le demander.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    set file_Name to (path to desktop folder as string) & "CECE:Factures.txt" -- Nom du fichier export
    set theOutputPath to (path to desktop folder as string) & "CECE:Fiches.txt" -- Nom du fichier modifié pour import
     
    display dialog "Cette application va transferer votre Facture en Fiche dans la société POPO" buttons {"Ok"} with icon note
     
    tell application "Microsoft Excel" -- Ouvrir excel
    	set silently of window 1 to true
    	set visible to false
    	open text file filename file_Name origin Macintosh data type delimited field info {{1, text format}, {2, text format}, {3, text format}} with tab -- Ourir le fichier export txt*
    	set value of cell ("A" & "1") to ""
    	set value of cell ("B" & "1") to "C" 
    	set value of cell ("B" & "4") to "SA"
    	set value of cell ("J" & "4") to "41"
    	set value of cell ("K" & "4") to ""
    	set value of cell ("AS" & "4") to cell ("L" & "4")
    	set value of cell ("L" & "4") to "SARL POPO"
    	set value of cell ("M" & "4") to ""
    	set value of cell ("N" & "4") to "ZZZZZZ"
    	set value of cell ("P" & "4") to "BEEEEEEEEE"
    	set value of cell ("Q" & "4") to "999999"
    	set value of cell ("R" & "4") to "MMMMMM"
    	set value of cell ("U" & "4") to "06 323 323 322"
    	set value of cell ("V" & "4") to "01 43 43 34 43"
    	set value of cell ("W" & "4") to "zzzzzz@orange.fr"
    	set value of cell ("X" & "4") to "FR"
    	set value of cell ("Y" & "4") to "0990909090"
    	set value of cell ("AR" & "4") to "Facture"
    	set value of cell ("AQ" & "4") to "aaaaaaaa"
    	set value of cell ("AU" & "4" & ":" & "BT" & "4") to ""
    	set I to 5 -- Boucle demarant à 5
    	repeat until (I = 100) -- jusqu'à 100. *
    		if value of cell ("B" & I) is not equal to "" then set value of cell ("B" & I) to "DIVERS" -- si B? n'est pas vide alors saisir vide (B = Code Produit)
    		if value of cell ("B" & I) is equal to "DIVERS" then set value of cell ("AD" & I) to "XXXX0XXXX1XXXX0XXXX0XXXX1XXXX0.989465XXXX0.069867XXXX0.043890"
    		if value of cell ("D" & I) is not equal to "" then set value of cell ("D" & I) to "" -- D = Px Unit
    		if value of cell ("G" & I) is not equal to "" then set value of cell ("G" & I) to "" -- G = Remise
    		if value of cell ("H" & I) is not equal to "" then set value of cell ("H" & I) to "" -- H = Code TVA
    		if value of cell ("I" & I) is not equal to "" then set value of cell ("I" & I) to "" -- I = Taux TVA
    		if value of cell ("J" & I) is not equal to "" then set value of cell ("J" & I) to "" -- J = Px Achat
    		set I to I + 1 -- augmenter la valeur de I +1
    		log I -- lit I
    	end repeat -- s'arreter si I = 100
     
    	tell active workbook
    		activate
    		save workbook as filename theOutputPath file format current platform text file format with «class 5321» and overwrite without asking -- Sauvegarder modifs dans nouveau fichier
    		delay 0.5
    		quit saving no -- fermer les fichiers excel
    	end tell
    end tell
    ....
    Merci d'avance

  2. #2
    Membre éprouvé

    Homme Profil pro
    Directeur de projet
    Inscrit en
    Septembre 2010
    Messages
    602
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Directeur de projet
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Septembre 2010
    Messages : 602
    Points : 1 239
    Points
    1 239
    Par défaut
    Bonsoir,
    Lorsque tu exécutes le "Save as", le dialogue demandant la confirmation pour le remplacement de l'ancien fichier Fiches.txt est demandé par l'OS.
    Comme cette demande ne vient ni de Excel, ni du script, tu ne peux intervenir directement dessus.

    Il faut en fait contourner le problème afin ... qu'il ne se produise plus !
    Pour cela, il faut, juste avant le "Save as", supprimer l'ancien fichier.

    Donc, dans ton script, juste avant la ligne "Save as", il faut insérer :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
            tell application "Finder" to delete file theOutputPath
    A noter que cette suppression étant faite par le Finder, l'ancienne version du fichier sera à la poubelle (au cas où !).

    Par ailleurs, j'ai eu un problème de compilation sur ton script pour la ligne "Save as" : la class que tu utilises est inconnue de mon compilateur (et de moi, malgré une recherche Google rapide). Idem avec "overwrite without asking". J'ai donc simplement mis :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    save workbook as filename theOutputPath file format current platform text file format
    Qui fonctionne parfaitement.

    Cordialement

Discussions similaires

  1. Réponses: 12
    Dernier message: 26/01/2012, 15h44
  2. DTS option pour vérifier si fichier Excel existe
    Par lazzeroni dans le forum MS SQL Server
    Réponses: 1
    Dernier message: 05/08/2009, 16h12
  3. Réponses: 4
    Dernier message: 26/05/2009, 09h15
  4. [POO] script pour remplacer un fichier image par un fichier flash
    Par tomguiss dans le forum Général JavaScript
    Réponses: 4
    Dernier message: 13/12/2008, 13h03
  5. Réponses: 4
    Dernier message: 14/05/2007, 10h50

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo