AutoHotkey Community
Let's help each other out
Skip to content
Post by joedf » 28 Jul 2020, 09:27
Code: Select all
; 1 : le remplacement de texte et création du nouveau doc.odt (ce que le script fait bien) ; code ... LeFichierODT := newFile ; 2 : l'aperçu du nouveau doc.odt j'insiste sur l'aperçu qui peut ce matérialiser par ; l'ouverture du nouveau doc.odt (étape qui me permet de contrôler les remplacements ; fait et me montré un erreur de saisie) ; ouvrir le doc avec libreoffice Run, soffice.exe "%LeFichierODT%",,,libreofficePID sleep 1000 ; attendre 1 seconde ; attendre pour l'apparition de la fenêtre WinWait , ahk_pid %libreofficePID%,, 3 ; timeout de 3 secondes ; libreoffice est là et prêt, ouvrir l’aperçu avec CTRL+ MAJ + O ControlSend,, ^+o, ahk_pid %libreofficePID% ; 3 : proposition oui ou non d'impression ; l'utilisateur a fermé libreoffice, impression? MsgBox, 36, , Voulez-vous imprimer le document modifié? IfMsgBox, Yes { ; 4 : action d'impression sur le cas ou oui est choisie sur la msgbox évidemment ; Oui, on imprime le document! Run, soffice.exe -p "%LeFichierODT%" } else { ; Non, on fait rien... }
Post by alexooo » 26 Jul 2020, 03:26
Post by joedf » 24 Jul 2020, 09:58
; 1 : le remplacement de texte et création du nouveau doc.odt (ce que le script fait bien) ; code ... LeFichierODT := "C:\Utilisateurs\Admin\Documents\MonFichier.odt" ; 2 : l'aperçu du nouveau doc.odt j'insiste sur l'aperçu qui peut ce matérialiser par ; l'ouverture du nouveau doc.odt (étape qui me permet de contrôler les remplacements ; fait et me montré un erreur de saisie) ; ouvrir le doc avec libreoffice Run, libreoffice.exe "%LeFichierODT%",,,libreofficePID sleep 1000 ; attendre 1 seconde ; attendre pour l'apparition de la fenêtre WinWait , ahk_pid %libreofficePID%,, 3 ; timeout de 3 secondes ; libreoffice est là et prêt, ouvrir l’aperçu avec CTRL+ MAJ + O ControlSend,, ^+o, ahk_pid %libreofficePID% ; 3 : proposition oui ou non d'impression ; l'utilisateur a fermé libreoffice, impression? MsgBox, 36, , Voulez-vous imprimer le document modifié? IfMsgBox, Yes { ; 4 : action d'impression sur le cas ou oui est choisie sur la msgbox évidemment ; Oui, on imprime le document! Run, libreoffice.exe -p "%LeFichierODT%" } else { ; Non, on fait rien... }
Post by alexooo » 24 Jul 2020, 04:11
Post by joedf » 23 Jul 2020, 16:36
Post by alexooo » 23 Jul 2020, 15:50
Post by joedf » 22 Jul 2020, 13:52
MsgBox, 36, , Voulez-vous imprimer le document modifié? IfMsgBox, Yes { ; Oui, on imprime le document! } else { ; Non, on fait rien... }
Post by alexooo » 22 Jul 2020, 11:41
if FileExist(DocumentODT) { ; Creer un dossier temporaire tmpDir := A_Temp "\tempODT" if FileExist(tmpDir) FileRemoveDir, %tmpDir%, 1 FileCreateDir, %tmpDir% fContentXML := "content.xml" tmpFile := tmpDir "\" fContentXML ; Extraire les fichiers 7z_extract(DocumentODT, tmpDir) ; lire le contenu de content.xml FileRead, fileContents, %tmpFile% ; modifier le contenu fileContents := ModifierLeContenu(fileContents) ; remplacer l'original FileDelete, %tmpFile% FileAppend, %fileContents%, %tmpFile% ; recombiner et recompresser le fichier SplitPath, DocumentODT,,,, fNameNoExt newFile := fNameNoExt ".nouveau.odt" if FileExist(newFile) FileDelete, %newFile% 7z_compressZIP(newFile, tmpDir "\*")
; Fin MsgBox, 64, Fini!, Le nouveau fichier "%newFile%" est cree. } else { MsgBox, 16, Erreur, Le fichier "%DocumentODT%" n'existe pas... } return
Post by joedf » 19 Nov 2019, 21:36
Post by alexooo » 19 Nov 2019, 14:04
Post by joedf » 18 Nov 2019, 22:02
Post by alexooo » 18 Nov 2019, 18:20
Post by joedf » 18 Nov 2019, 17:49
Post by alexooo » 18 Nov 2019, 15:19
Post by alexooo » 18 Nov 2019, 14:41
Post by joedf » 18 Nov 2019, 12:03
#NoEnv SetWorkingDir %A_ScriptDir% ; spécifier l'exécutable 7z 7z_exe:="7za.exe" DocumentODT := "Test2.odt" if FileExist(DocumentODT) { ; Creer un dossier temporaire tmpDir := A_Temp "\tempODT" if FileExist(tmpDir) FileRemoveDir, %tmpDir%, 1 FileCreateDir, %tmpDir% fContentXML := "content.xml" tmpFile := tmpDir "\" fContentXML ; Extraire les fichiers 7z_extract(DocumentODT, tmpDir) ; lire le contenu de content.xml FileRead, fileContents, %tmpFile% ; modifier le contenu fileContents := ModifierLeContenu(fileContents) ; remplacer l'original FileDelete, %tmpFile% FileAppend, %fileContents%, %tmpFile% ; recombiner et recompresser le fichier SplitPath, DocumentODT,,,, fNameNoExt newFile := fNameNoExt ".nouveau.odt" if FileExist(newFile) FileDelete, %newFile% 7z_compressZIP(newFile, tmpDir "\*") ; Fin MsgBox, 64, Fini!, Un nouveay fichier "%newFile%" a été créé. } else { MsgBox, 16, Erreur, Le fichier "%DocumentODT%" n'existe pas... } return ModifierLeContenu(data) { FRS2 := "42" ADRESSE := "42 rue Allouette" CP := "AZERTY" REJET := "Non, jamais :(" StringReplace, data, data, FOURNISSEUR, %FRS2% StringReplace, data, data, ADRESSE, %ADRESSE% StringReplace, data, data, POSTAL, %CP% StringReplace, data, data, NUMERO, %REJET% return data } ;modification de 7z wrapper - par joedf ; https://autohotkey.com/boards/viewtopic.php?f=6&t=3892 7z_compressZIP(dPack,files*) { global 7z_exe flist:="" for each, file in files flist:= flist """" file """" " " if FileExist(dPack) FileDelete, %dPack% RunWait, %7z_exe% a -tZip "%dPack%" %flist%,,Hide UseErrorLevel return !7z_error(ErrorLevel) } 7z_extract(dPack,dFolder="",opts="") { global 7z_exe if StrLen(dFolder) out:="-o" . """" . dFolder . """" RunWait, %7z_exe% x "%dPack%" %out% -y %opts%,,Hide UseErrorLevel return !7z_error(ErrorLevel) } 7z_error(e) { if (e==1) MsgBox, 48, 7zip Error, Warning (Non fatal error(s)). For example, one or more files were locked by some other application, so they were not compressed. else if (e==2) MsgBox, 48, 7zip Error, Fatal error else if (e==7) MsgBox, 48, 7zip Error, Command line error else if (e==8) MsgBox, 48, 7zip Error, Not enough memory for operation else if (e==255) MsgBox, 48, 7zip Error, User stopped the process return e }
Post by joedf » 17 Nov 2019, 22:14
Post by alexooo » 16 Nov 2019, 02:59
Post by joedf » 15 Nov 2019, 16:10
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <office:document-content xmlns:anim="urn:oasis:names:tc:opendocument:xmlns:animation:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:smil="urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xlink="http://www.w3.org/1999/xlink"> <office:font-face-decls> <style:font-face style:name="Calibri" svg:font-family="Calibri" style:font-family-generic="swiss" style:font-pitch="variable" svg:panose-1="2 15 5 2 2 2 4 3 2 4"/> <style:font-face style:name="Times New Roman" svg:font-family="Times New Roman" style:font-family-generic="roman" style:font-pitch="variable" svg:panose-1="2 2 6 3 5 4 5 2 3 4"/> <style:font-face style:name="Arial" svg:font-family="Arial" style:font-family-generic="swiss" style:font-pitch="variable" svg:panose-1="2 11 6 4 2 2 2 2 2 4"/> <style:font-face style:name="Cambria" svg:font-family="Cambria" style:font-family-generic="roman" style:font-pitch="variable" svg:panose-1="2 4 5 3 5 4 6 3 2 4"/> </office:font-face-decls> <office:automatic-styles> <style:style style:name="P1" style:parent-style-name="Normal" style:master-page-name="MP0" style:family="paragraph"> <style:paragraph-properties fo:break-before="page" fo:margin-top="0.0694in" fo:margin-bottom="0in" fo:line-height="100%"/> </style:style> <style:style style:name="T2" style:parent-style-name="Policepardéfaut" style:family="text"> <style:text-properties style:font-name="Times New Roman" style:font-name-asian="Times New Roman" fo:color="#000000" style:language-asian="fr" style:country-asian="FR"/> </style:style> <style:style style:name="P3" style:parent-style-name="Normal" style:family="paragraph"> <style:paragraph-properties fo:margin-top="0.0694in" fo:margin-bottom="0in" fo:line-height="100%"/> <style:text-properties style:font-name="Arial" style:font-name-asian="Times New Roman" style:font-name-complex="Arial" fo:color="#000000" fo:font-size="8pt" style:font-size-asian="8pt" style:font-size-complex="8pt" style:language-asian="fr" style:country-asian="FR"/> </style:style> <style:style style:name="P4" style:parent-style-name="Normal" style:family="paragraph"> <style:paragraph-properties fo:margin-top="0.0694in" fo:margin-bottom="0in" fo:line-height="100%"/> <style:text-properties style:font-name="Arial" style:font-name-asian="Times New Roman" style:font-name-complex="Arial" fo:color="#000000" fo:font-size="8pt" style:font-size-asian="8pt" style:font-size-complex="8pt" style:language-asian="fr" style:country-asian="FR"/> </style:style> <style:style style:name="P5" style:parent-style-name="Normal" style:family="paragraph"> <style:paragraph-properties fo:margin-top="0.0694in" fo:margin-bottom="0in" fo:line-height="100%" fo:margin-left="4.9166in"> <style:tab-stops/> </style:paragraph-properties> </style:style> <style:style style:name="T6" style:parent-style-name="Policepardéfaut" style:family="text"> <style:text-properties style:font-name="Times New Roman" style:font-name-asian="Times New Roman" fo:color="#000000" style:language-asian="fr" style:country-asian="FR"/> </style:style> <style:style style:name="P7" style:parent-style-name="Normal" style:family="paragraph"> <style:paragraph-properties fo:margin-left="4.425in" fo:text-indent="0.4916in"> <style:tab-stops/> </style:paragraph-properties> <style:text-properties style:font-name="Times New Roman" style:font-name-asian="Times New Roman" fo:color="#000000" style:language-asian="fr" style:country-asian="FR"/> </style:style> <style:style style:name="P8" style:parent-style-name="Normal" style:family="paragraph"> <style:text-properties style:font-name="Times New Roman" style:font-name-asian="Times New Roman" fo:color="#000000" style:language-asian="fr" style:country-asian="FR"/> </style:style> <style:style style:name="P9" style:parent-style-name="Normal" style:family="paragraph"> <style:text-properties style:font-name="Times New Roman" style:font-name-asian="Times New Roman" fo:color="#000000" style:language-asian="fr" style:country-asian="FR"/> </style:style> <style:style style:name="P10" style:parent-style-name="Normal" style:family="paragraph"> <style:text-properties style:font-name="Times New Roman" style:font-name-asian="Times New Roman" fo:color="#000000" style:language-asian="fr" style:country-asian="FR"/> </style:style> <style:style style:name="P11" style:parent-style-name="Normal" style:family="paragraph"> <style:text-properties style:font-name="Times New Roman" style:font-name-asian="Times New Roman" fo:color="#000000" style:language-asian="fr" style:country-asian="FR"/> </style:style> <style:style style:name="T12" style:parent-style-name="Policepardéfaut" style:family="text"> <style:text-properties style:font-name="Times New Roman" style:font-name-asian="Times New Roman" fo:color="#000000" style:language-asian="fr" style:country-asian="FR"/> </style:style> </office:automatic-styles> <office:body> <office:text text:use-soft-page-breaks="true"> <text:p text:style-name="P1"> <text:span text:style-name="T2">FOURNISSEUR</text:span> </text:p> <text:p text:style-name="P3"/> <text:p text:style-name="P4"/> <text:p text:style-name="P5"> <text:span text:style-name="T6">ADRESSE</text:span> </text:p> <text:p text:style-name="P7">CP</text:p> <text:p text:style-name="P8"/> <text:p text:style-name="P9"/> <text:p text:style-name="P10"/> <text:p text:style-name="P11"/> <text:p text:style-name="Normal"> <text:span text:style-name="T12">NUMERO</text:span> </text:p> </office:text> </office:body> </office:document-content>
Post by alexooo » 13 Nov 2019, 15:24
Top