问题
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?
回答1:
From the write-only mode docs:
In a write-only workbook, rows can only be added with
append()
. It is not possible to write (or read) cells at arbitrary locations withcell()
oriter_rows()
.
来源:https://stackoverflow.com/questions/44313365/why-does-a-writeonlyworksheet-object-have-no-attribute-cell