Tartalomjegyzék

< Python

Python Excel

Telepítés

pip install openpyxl

Munkafüzet készítése

main.py
from openpyxl import Workbook
 
wb = Workbook()
ws = wb.active
ws['B2'] = 25
path = 'valami.xlsx'
wb.save(path)

Munkalapok kiíratása

main.py
from openpyxl import load_workbook
 
path = 'valami.xlsx'
wb = load_workbook(path)
 
print(wb.sheetnames)
 
wb.save(path)

Munkafüzet írása

main.py
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

main.py
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

main.py
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

main.py
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