微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

无法写入excel AttributeError:“工作表”对象没有属性“写入”

我正在尝试向Excel编写文本,我正在关注此post.这以前工作正常,但现在却没有.我得到:

错误

line 122, in <module>
    worksheet.write(0, 11, 'HI')
AttributeError: 'Worksheet' object has no attribute 'write'

df1

A  E
c  d
c  D

码:

writer = pd.ExcelWriter("C:\\33.xlsx")
df1.to_excel(writer, startrow=0, startcol=0, index = False)

worksheet = writer.sheets['Sheet1']
worksheet.write(0, 11, 'YO')
worksheet.write(1, 11, 'HI')

我也尝试过:

import xlrd
import xlwt
from xlutils.copy import copy
import os.path
rb = xlrd.open_workbook('C:\\13.xlsx',formatting_info=True)
r_sheet = rb.sheet_by_index(0) 
wb = copy(rb) 
sheet = wb.get_sheet(0) 
sheet.write(5,2,"string")
wb.save('C:\\13.xlsx')

我得到:

    with open(filename, "rb") as f:
OSError: [Errno 22] Invalid argument: 'C:\\13.xlsx"'

如何修复AttributeError:“工作表”对象没有属性“写”

解决方法:

它给出的原因:AttributeError:“工作表”对象没有属性“写”

是因为我意识到我尚未在此PC上安装xlsxwriter.

pip install xlsxwriter

现在可以了.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐