B
B
badrbot2019-03-22 19:16:16
Python
badrbot, 2019-03-22 19:16:16

How to make openpyxl save data to excel?

There is a function that creates an excel file and sends data there.
Only it is called many times because of this, the data is not saved, I need a function to save the data, and when the program ends, it will save the data to a file

from openpyxl import Workbook

def excel_write(name, doljnost, place, money_min, money_max, money_for_hour_min, money_for_hour_max, url):
    wb = Workbook()
    ws = wb.active
    
    ws['A1'] = 'Название'
    ws['B1'] = 'Должность'
    ws['C1'] = 'Место'
    ws['D1'] = 'Зарплата min'
    ws['E1'] = 'Зарплата max'
    ws['F1'] = 'Зарплата За час, min'
    ws['G1'] = 'Зарплата За час, max'
    ws['H1'] = 'Ссылка'
    ws.append([name, doljnost, place, money_min, money_max, money_for_hour_min, money_for_hour_max, url])
    wb.save("sample1.xlsx")

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dimonchik, 2019-03-22
@acrytzat

shove everything into a list of lists
then open the book, enter the list of lists in a loop, close

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question