我正在尝试上载我的代码,该代码使用google sheets文件上的pandas数据帧值将条件格式应用于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
见文件here。另请参见readme中的示例
相关问题 更多 >
编程相关推荐