Aprenda como a editar arquivos do excel diretamente no python, como um substituto do VBA, através da biblioteca openpyxl. Nessa biblioteca você pode executar tarefas diversas, como carregar e editar valores, alterar a formatação, bordas e cores das células e fontes, criar e excluir linhas, colunas, células e planilhas, inserir fórmulas e muito mais.
Códigos útilizados:
!pip install openpyxl
from openpyxl import *
workbook = load_workbook(filename="testes/teste.xlsx")
workbook.save(filename="testes/teste.xlsx")
workbook = Workbook()
sheet = workbook.active
sheet = workbook['Sheet']
sheet['A1'].value
sheet['A1'] = ‘b’
sheet.cell(row=1, column=1).value
sheet.cell(row=1, column=3, value=0)
sheet['A1:C2']
for row in sheet.iter_rows():
print(row)
for cols in sheet.iter_cols():
print(cols)
sheet['C2'] = '=AVERAGE(A1:A5)1
Playlist sobre PANDAS: • Pandas
Playlist sobre PYTHON: • Python
Playlist sobre GRÁFICOS: • Gráficos
Playlist sobre JUPYTER: • Jupyter Notebook
#python #openpyxl #excel #vba #células #ler #carregar #salvar #fórmulas
0:00 Introdução
0:44 Instalando a biblioteca
1:11 Criando uma planilha do Excel
2:03 Salvando o arquivo
2:24 Lendo um arquivo do excel
2:39 Carregando o nome das planilhas do Excel
3:14 Editando células da planilha
4:06 Trabalhando com várias células
5:38 Inserindo fórmulas do Excel
6:12 Outras funções do Openpyxl
6:34 Encerramento