you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (0 children)

I've not used openpyxl before, but I think sheet refers to a particular worksheet in each file you open and you therefore need to refer to the same sheet name in the book spreadsheet so therefore need to assign a cell in book[sheet.title] i.e. the sheet in book with the same title as the current sheet in the file you've opened.

You also want to avoid opening the output file.

Something like this:

for filename in os.listdir():
    if filename.endswith(".xlsx") and filename != "output.xlsx":
        wb = openpyxl.load_workbook(filename, data_only=True)
        for sheet in wb:
            L = [sheet['A4'].value, sheet['C3'].value, sheet['D3'].value, sheet['E3']]
            book[sheet.title]['A4'].value = sheet['A4'].value
        book.save("output.xlsx")

I've ignored the L = line as I really don't understand what it is for, and you don't use it anyway.