1
Good afternoon!
I already know how to create a spreadsheet in Excel by Python, when I know exactly which columns I need to create. But how can I make the creation of columns dynamic? for example:
to create a simple spreadsheet, I use the Workbook library and do so:
from openpyxl import Workbook
book = Workbook()
sheet = book.active
nome_xlsx = 'teste.xlsx'
sheet['A1'] = 'ID1'
sheet['B1'] = 'ID2'
sheet['C1'] = 'ID3'
sheet['D1'] = 'ID4'
sheet['E1'] = 'ID5'
lista_de_ordenacao = list(string.ascii_uppercase)
cont = 2
for item in lista_de_ordenacao:
item1 = item[0]
sheet['A'+str(cont)] = int(item1)
item2 = item[1]
sheet['B'+str(cont)] = str(item2)
item3 = item[2]
sheet['C'+str(cont)] = str(item3)
item4 = item[3]
sheet['D'+str(cont)] = str(item4)
item5 = item[4]
sheet['E'+str(cont)] = str(item5)
cont = cont + 1
book.save(nome_xlsx)
But, as I would create for example, 100 columns so I don’t have to manually type in the code sheet['CV1'] = 'qualquer coisa'
?
In my case, I need to make several spreadsheets with matrices, so some may have 100 rows and 100 columns, others may have 1000 rows and 1000 columns
This value varies according to the data I need to put in the matrix
Thank you for your attention!