Skip to content

Traitement des fichiers xlsx (via Google Drive)

loup-brun edited this page Dec 11, 2019 · 1 revision
  1. Enregister le fichier xlsx
  2. Effectuer le traitement avec la marco (exemple avec LibreOffice ci-dessous) : nettoyer et remplacer valeurs
  3. Transposer (rangées en colonnes)
  4. Exporter toutes les feuilles en csv
  5. Convertir les fichiers csv vers yaml
  6. Réunir les fichiers yaml en 1 fichier yaml 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
Clone this wiki locally