AttributeError: ‘WriteOnlyWorksheet’ object has no attribute ‘cell’
今天打算写一个可以合并excel文件的python程序,在最后创建工作簿并写入数据的时候出现了一些问题。
import openpyxl
wb=openpyxl.Workbook("save.xlsx")
wb.create_sheet(index=0, title=“Sheet 1”)
sheet=wb.get_sheet_by_name(“Sheet 1”)
sheet.cell(column=1,row=1).value= 1
wb.save("save.xlsx")
上面是我的创建工作簿的代码
AttributeError: 'WriteOnlyWorksheet' object has no attribute 'cell'
上面是出现的问题
经过查阅一些资料,问题应该是在创建工作簿的时候,不能够同时写入数据,所以我把工作簿创建好,保存,然后再打开,数据就可以写入了。