[英]'Worksheet' object has no attribute 'cell'
I need to open an xlsx document and color it.我需要打开一个 xlsx 文档并为其着色。 But I don't understand why it shows cell error it.但我不明白为什么它会显示单元格错误。 My algorithm works like this:我的算法是这样工作的:
Open xlsx, writer = pd.ExcelWriter(path, engine='xlsxwriter')
打开 xlsx, writer = pd.ExcelWriter(path, engine='xlsxwriter')
worksheet = writer.sheets['Sheet1']
col_style = Font(name = "Reem Kufi", size = 12, color = "DB3B22", italic =True)
for i in range(2,40):
worksheet.cell(row = i, column = 3).font = col_style
Error:- 'Worksheet' object has no attribute 'cell'错误:- “工作表”对象没有属性“单元格”
you will need to use Openpyxl's loadworkbook
instead of ExcelWriter
to achieve what you are looking for.您将需要使用 Openpyxl 的loadworkbook
而不是ExcelWriter
来实现您正在寻找的内容。 Updated code here.在这里更新了代码。 Note that I have only changed the initial open file and sheet using the new code and required libraries and not changed rest of your code.请注意,我只使用新代码和所需的库更改了初始打开的文件和工作表,而没有更改您的其余代码。
from openpyxl.styles import Font
from openpyxl import load_workbook
writer = load_workbook(filename='YourFile.xlsx')
worksheet = writer['Sheet1']
col_style = Font(name = "Reem Kufi", size = 12, color = "DB3B22", italic =True)
for i in range(2,40):
worksheet.cell(row = i, column = 3).font = col_style
writer.save('YourFile.xlsx')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.