-
Notifications
You must be signed in to change notification settings - Fork 0
Traitement des fichiers xlsx (via Google Drive)
loup-brun edited this page Dec 11, 2019
·
1 revision
- Enregister le fichier xlsx
- Effectuer le traitement avec la marco (exemple avec LibreOffice ci-dessous) : nettoyer et remplacer valeurs
- Transposer (rangées en colonnes)
- Exporter toutes les feuilles en
csv
- Convertir les fichiers
csv
versyaml
- Réunir les fichiers
yaml
en 1 fichieryaml
final.
Macro LibreOffice Basic :
Sub NettoyageHL
'==============
Dim oSheets As Variant
Dim oSheet As Variant
Dim oColumns As Variant
Dim oDictionary as Variant
Dim oSearchDescriptor as Variant
Dim oReplace as Variant
Dim i As Long, j As Long
s = 0
oSheets = ThisComponent.getSheets() ' All sheets
oDoc = ThisComponent
oStatusIndicator = oDoc.getCurrentController().getStatusIndicator() ' what's this?
Do While oSheets.Count > s
oSheet = oSheets.getByIndex(s)
oColumns = oSheet.getColumns() ' All columns of this sheet as object (with some metods)
oRows = oSheet.getRows()
oColumns.removeByIndex(2, 1) ' Remove 3rd column
oRows.removeByIndex(0, 2) ' Remove first 2 rows
oDictionary = Array( _
Array("id", "Identifiant"), _
Array("type", "Type"), _
Array("title", "Titre"), _
Array("author", "Nom de l'auteur"), _
Array("content", "Commentaire ou description de l'augmentation *"), _
Array("copyright", "Copyright *"), _
Array("year", "Année de publication *"), _
Array("src", "Fichier média *"), _
Array("location", "Emplacement *"), _
Array("medium", "Medium *"), _
Array("caption", "Légende") )
oSearchDescriptor = oSheet.createSearchDescriptor() ' begin search
oStatusIndicator.start("", UBound(oDictionary)+1)
For i = LBound(oDictionary) To UBound(oDictionary)
oReplace = oDictionary(i)
oSearchDescriptor.setReplaceString(oReplace(0))
oStatusIndicator.setText(oDictionary(i)(0))
oStatusIndicator.setValue(i + 1)
For j = 1 To UBound(oReplace)
oSearchDescriptor.setSearchString(oReplace(j))
oSheet.replaceAll(oSearchDescriptor)
Next j
Next i
oStatusIndicator.end()
s = s + 1
Loop
End Sub