我正在尝试使用Google表格文件上的pandas dataframe值上传将条件格式应用于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 Write,我可以运行我的代码而没有任何问题,但是使用pygsheets不能使用相同的方法。谁知道我该如何使用pygsheets应用这种条件格式?
谢谢!
请wks.add_conditional_formatting
用于应用条件格式。请注意,由于尚未在pypi中发布,因此请使用暂存版本。
pip安装-升级https://github.com/nithinmurali/pygsheets/archive/staging.zip
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句