我试图上传我的代码,应用条件格式的Excel文件使用熊猫数据格式值的谷歌工作表文件。
为此,我有以下代码:
import pygsheets
import pandas as pd
gc = pygsheets.authorize(service_file="")
wsh = gc.open_by_url('')
sheet = wsh[0]
my_formats = {}
for index, row in df.iterrows():
if 'PC' in row['ID']:
my_formats['"' + row['ID'] + '"'] = '#C00000'
else:
my_formats['"' + row['ID'] + '"'] = '#010203'
sheet.set_dataframe(df, 'A2')
for val, color in my_formats.items():
fmt = wsh.add_format({'bold':True,'font_color': color})
wsh.conditional_format('F2:F50000', {'type': 'cell',
# 'bold': True,
'criteria': '=',
'value': val,
'format': fmt})使用Pandas DataFrame Excel,我能够运行我的代码,没有任何问题,但是使用pygsheets的方法是行不通的。有人知道如何使用pygsheets应用这种条件格式设置吗?
谢谢!
发布于 2020-12-26 17:53:35
请使用wks.add_conditional_formatting应用条件格式。请注意,由于这尚未在pypi中发布,所以请使用暂存版本。
pip安装--升级https://github.com/nithinmurali/pygsheets/archive/staging.zip
https://stackoverflow.com/questions/65455992
复制相似问题