====== Description ====== Je vais un petit peu expliquer la macro permettant de générer les cours élève, elle est écrite en Basic attention ce n'est pas du VBA et cela fait appel à lAPI de libreOffice qui lui est spécifique. ====== Macro pour générer les cours élèves ====== REM ***** BASIC ***** Sub Main repBase="/home/cemoi/ownCloud/SFTP/Travail_en_service/" 'chemin à adapter ' boucle sur les repertoires et sous repertoires et traitement des fichiers call boucleRepertoire(convertToUrl(repBase)) msgBox "Fin du traitement" End Sub sub boucleRepertoire(sUrl) Dim oSFA As Object, oDateFile As Object Dim Mois As Long, DateJours As Long, Heure As Long Dim sNom As String Dim ListeFichiers As Variant oSFA = createUnoService("com.sun.star.ucb.SimpleFileAccess") ListeFichiers = oSFA.getFolderContents(sUrl, True) Mois = Month(Now)'on recupére la date du jour (mois jour heure) DateJours = Day(Now) Heure = Hour(Now) for each sNom in ListeFichiers if oSFA.IsFolder(sNom) then call boucleRepertoire(sNom) ' appel recursif else if endWith(sNom,".odt") and (not endWith(sNom,"_eleve.odt")) and instr(sNom,"cours") > 0 then oDateFile = oSFA.getDateTimeModified(convertToURL(sUrl)) 'if oDateFile.day = DateJours And oDateFile.Month = Mois and oDateFile.hours < 1 Then 'on definit ds quelle condition de temps les fichiers doivent etre traité call traiteFichier(sNom) ' on traite ce fichier End if End if 'End if next sNom end sub function endWith(chaine, cherche) endWith = ( right(chaine, len(cherche)) = cherche) end function sub traiteFichier(urlFichier) ' ouverture doc = starDesktop.loadComponentFromUrl(urlFichier,"_blank",0, array()) ' traitement des styles call RemplacerStylePartout2(doc) ' nom de fichier de sortie spliter = split(doc.url, ".") ' decoupe la chaine avec les points nb = ubound(spliter) spliter(nb-1) = spliter(nb-1)+"_eleve" spliter(nb)="pdf" newUrlPdf = join(spliter,".") 'spliter(nb)="odt" 'newUrlOdt = join(spliter,".") 'enregistrement nouveau odt 'doc.storeAsUrl(newUrlOdt, array()) ' aucune option, array vide ' options de l'export pdf dim propsFiltre(0 to 0) as new com.sun.star.beans.PropertyValue propsFiltre(0).name = "IsSkipEmptyPages" propsFiltre(0).value = False dim prop(0 to 1) as new com.sun.star.beans.PropertyValue prop(0).name="FilterName" prop(0).value = "writer_pdf_Export" prop(1).name="FilterData" prop(1).value = propsFiltre() ' export pdf doc.storeToUrl(newUrlPdf, prop() ) ' on ferme le fichier initial sans modification doc.close(false) end sub Sub RemplacerStylePartout2(MonDocument) Dim JeCherche As Object JeCherche = MonDocument.createReplaceDescriptor with JeCherche .SearchString = "Texte eleve visible" .ReplaceString = "Texte eleve invisible" .SearchStyles = true end with MonDocument.replaceAll(JeCherche) End Sub