user8128927
user8128927

Reputation:

python3 openpyxl not writing to cell

Hello I am having issues writing to an a file using the openpyxl module. I am trying for a simple test What am I doing wrong?

def readInWorkbook():
wb = load_workbook(filename = 'myTracker.xlsx')
wb['A1'] = 'HEY we made it'
wb.save('myTracker.xlsx')
print("After save")

the error that I get is File "tracker.py", line 10, in readInWorkbook wb['A1'] = 'HEY we made it' AttributeError: setitem

Thank you.

Upvotes: 0

Views: 312

Answers (1)

Abbas
Abbas

Reputation: 4069

You are trying to write to a work book, where as you need to write to a work sheet.

def readInWorkbook():
    wb = load_workbook(filename = 'myTracker.xlsx')
    #Get active work sheet  
    ws = wb.active
    ws['A1'] = 'HEY we made it'
    wb.save('myTracker.xlsx')
    print("After save")

Upvotes: 1

Related Questions