简体   繁体   English

“工作表”对象没有属性“单元格”

[英]'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.

相关问题 “工作表” object 没有属性“电子表格” - 'Worksheet' object has no attribute 'spreadsheets' openpyxl'工作表'对象没有属性'写'(python) - openpyxl 'Worksheet' object has no attribute 'write'(python) '工作表' object 没有属性 'set_column' - 'Worksheet' object has no attribute 'set_column' Openpyxl:“工作表”对象没有属性“值” - Openpyxl: 'Worksheet' object has no attribute 'values' “ AttributeError:“工作表”对象没有属性“工作表””是什么意思? - What does “AttributeError: 'Worksheet' object has no attribute 'worksheet' ” mean? 模块“gspread.worksheet”没有属性“update_cell” - module 'gspread.worksheet' has no attribute 'update_cell' `iter_cols` 给出一个工作表对象没有属性错误? - `iter_cols` gives a worksheet object has no attribute error? 无法写入excel AttributeError:'Worksheet'对象没有属性'write' - Cannot write to an excel AttributeError: 'Worksheet' object has no attribute 'write' AttributeError: 'Worksheet' 对象没有属性 'hide_gridlines' - AttributeError: 'Worksheet' object has no attribute 'hide_gridlines' AttributeError:“工作表”object 没有属性“插入行” - AttributeError: 'Worksheet' object has no attribute 'insert_row'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM