Python : Fichiers Excel
Aller à la navigation
Aller à la recherche
OpenPyXl
Cette lib permet de lire les fichiers excel assez facilement.
<source lang="python">
- !/usr/bin/env python3
- coding: utf-8
import openpyxl
- Charge le chemin du fichier -_-'
excelfile = Path('.', 'triage-lvg.xlsx')
- Charge le workbook (assemblage de worksheets, un fichier excel ayant plusieurs pages)
wb_obj = openpyxl.load_workbook(excelfile)
- Charge la sheet
sheet = wb_obj.active
- Affiche le nom de la sheet
print(sheet)
- Afficher le contenu
for row in sheet.iter_rows(max_row=sheet.max_row):
for cell in row: print(cell.value, end=" ") print()
- Fichier excel vers dictionnaire
content = {} i = 0
for row in sheet.iter_rows(max_row=sheet.max_row):
content[i] = [] for cell in row: content[i].append(cell.value) i += 1
for j in content.keys():
print(content[j])
</source>