【发布时间】:2023-03-10 21:33:02
【问题描述】:
我想通过这段代码使用 python 突出显示一个单元格。
writer = pd.ExcelWriter('4.xlsx', engine='xlsxwriter')
df.to_excel(writer, sheet_name='Sheet1')
writer.save()
Num_cols = len (df10.TIME1)
print(Num_cols)
for k in range(0, Num_cols):
a=0
if df10["TIME1"][k]!=df10["TIME2"][k]:
b=str(k)
a='E'+b
print(a)
print(df10["TIME1"][k],df10["TIME2"][k])
writer = pd.ExcelWriter('4.xlsx', engine='xlsxwriter')
df10.to_excel(writer, sheet_name='Sheet1')
workbook = writer.book
worksheet = writer.sheets['Sheet1']
worksheet.conditional_format(a, {'type': '2_color_scale'})
writer.save()
但它不适用于此代码。如果我使用此行
worksheet.conditional_format('E3', {'type': '2_color_scale'})
而不是这一行。E3 被突出显示。
worksheet.conditional_format(a, {'type': '2_color_scale'})
我的手机号码是可变的。我也尝试定义像这样的“a”值a="'"+a+"'",但我得到像AttributeError: 'NoneType' object has no attribute 'group'这样的错误
感谢您的回答。
【问题讨论】:
标签: excel python-3.x pandas