pandas 无法写入 Excel AttributeError: 'Worksheet' 对象没有属性 'write'
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47786882/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot write to an excel AttributeError: 'Worksheet' object has no attribute 'write'
提问by
I am trying to write text to an excel I am following this post. This was working earlier but now it is not. I get:
我正在尝试将文本写入我正在关注这篇文章的 excel 。这在早些时候有效,但现在不是。我得到:
Error:
错误:
line 122, in <module>
worksheet.write(0, 11, 'HI')
AttributeError: 'Worksheet' object has no attribute 'write'
df1
df1
A E
c d
c D
Code:
代码:
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')
I have tried also:
我也试过:
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')
I get:
我得到:
with open(filename, "rb") as f:
OSError: [Errno 22] Invalid argument: 'C:\13.xlsx"'
How do I fix AttributeError: 'Worksheet' object has no attribute 'write'
我该如何解决 AttributeError: 'Worksheet' object has no attribute 'write'
回答by
The reason it gives: AttributeError: 'Worksheet' object has no attribute 'write'
它给出的原因: AttributeError: 'Worksheet' object has no attribute 'write'
Is because I realised I have not installed xlsxwriter on this pc.
是因为我意识到我没有在这台电脑上安装 xlsxwriter。
pip install xlsxwriter
Now it works.
现在它起作用了。