[[oktatas:programozás:python|< Python]]
====== Python Excel ======
* **Szerző:** Sallai András
* Copyright (c) 2021, Sallai András
* Licenc: [[https://creativecommons.org/licenses/by-sa/4.0/|CC BY-SA 4.0]]
* Web: https://szit.hu
===== Telepítés =====
pip install openpyxl
===== Munkafüzet készítése =====
from openpyxl import Workbook
wb = Workbook()
ws = wb.active
ws['B2'] = 25
path = 'valami.xlsx'
wb.save(path)
===== Munkalapok kiíratása =====
from openpyxl import load_workbook
path = 'valami.xlsx'
wb = load_workbook(path)
print(wb.sheetnames)
wb.save(path)
===== Munkafüzet írása =====
from openpyxl import load_workbook
path = 'valami.xlsx'
wb = load_workbook(path)
sheet = wb.worksheets[0]
sheet.cell(row = 1, column = 1).value = 35
sheet.cell(row = 2, column = 1).value = 42
sheet.cell(row = 3, column = 1).value = 16
sheet.cell(row = 4, column = 1).value = '=sum(a1:a3)'
wb.save(path)
===== Munkafüzet írása másként =====
from openpyxl import load_workbook
path = 'valami.xlsx'
wb = load_workbook(path)
sheet = wb.worksheets[0]
sheet['a1'] = 25
sheet['a2'] = 42
sheet['a3'] = 15
sheet['a4'] = '=sum(a1:a3)'
wb.save(path)
===== Munkalap olvasása =====
from openpyxl import load_workbook
path = 'valami.xlsx'
wb = load_workbook(path)
sheet = wb.active
cell = sheet.cell(row = 2, column = 2)
print(cell.value)
===== Munkalap választással olvasás =====
from openpyxl import load_workbook
path = 'valami.xlsx'
wb = load_workbook(path)
sheet = wb.worksheets[0]
cell = sheet.cell(row = 2, column = 2)
print(cell.value)
===== Linkek =====
* https://openpyxl.readthedocs.io/en/stable/ (2021)
* https://www.geeksforgeeks.org/python-reading-excel-file-using-openpyxl-module/ (2021)