openpyxl - criando uma planilha do Excel (Workbook e Worksheet)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
# openpyxl para arquivos Excel xlsx, xlsm, xltx e xltm (instalação)
|
||||
# openpyxl - criando uma planilha do Excel (Workbook e Worksheet)
|
||||
# Com essa biblioteca será possível ler e escrever dados em células
|
||||
# específicas, formatar células, inserir gráficos,
|
||||
# criar fórmulas, adicionar imagens e outros elementos gráficos às suas
|
||||
@@ -7,3 +7,35 @@
|
||||
# manipulação de grandes quantidades de informações.
|
||||
# Instalação necessária: pip install openpyxl
|
||||
# Documentação: https://openpyxl.readthedocs.io/en/stable/
|
||||
from pathlib import Path
|
||||
|
||||
from openpyxl import Workbook
|
||||
from openpyxl.worksheet.worksheet import Worksheet
|
||||
|
||||
ROOT_FOLDER = Path(__file__).parent
|
||||
WORKBOOK_PATH = ROOT_FOLDER / 'workbook.xlsx'
|
||||
|
||||
workbook = Workbook()
|
||||
worksheet: Worksheet = workbook.active
|
||||
|
||||
# Criando os cabeçalhos
|
||||
worksheet.cell(1, 1, 'Nome')
|
||||
worksheet.cell(1, 2, 'Idade')
|
||||
worksheet.cell(1, 3, 'Nota')
|
||||
|
||||
students = [
|
||||
# nome idade nota
|
||||
['João', 14, 5.5],
|
||||
['Maria', 13, 9.7],
|
||||
['Luiz', 15, 8.8],
|
||||
['Alberto', 16, 10],
|
||||
]
|
||||
|
||||
# for i, student_row in enumerate(students, start=2):
|
||||
# for j, student_column in enumerate(student_row, start=1):
|
||||
# worksheet.cell(i, j, student_column)
|
||||
|
||||
for student in students:
|
||||
worksheet.append(student)
|
||||
|
||||
workbook.save(WORKBOOK_PATH)
|
||||
|
||||
BIN
aula199/workbook.xlsx
Normal file
BIN
aula199/workbook.xlsx
Normal file
Binary file not shown.
Reference in New Issue
Block a user