Why does a 'WriteOnlyWorksheet' object have no attribute 'cell'?

Viewed 5240
import openpyxl

wb=openpyxl.Workbook("multiplication.xlsx")
wb.create_sheet()
sheet=wb.get_active_sheet()

sheet.cell(column=6, row=4).value= 5

wb.save("multiplication.xlsx")

When i try and write in the cell, I receive this error.

Traceback (most recent call last):
  File "/Users/bjg/Desktop/excel2.py", line 8, in <module>
    sheet.cell(column=6, row=4).value= 5
AttributeError: 'WriteOnlyWorksheet' object has no attribute 'cell'

I was wondering if anybody knew why this was the case?

2 Answers

Instead of doing:

wb=openpyxl.Workbook("multiplication.xlsx")

just do:

wb=openpyxl.Workbook()

then at last save with:

wb.save("multiplication.xlsx")
Related