Python条件格式Google Sheets“电子表格”对象没有属性“add\u format”

2024-09-26 18:19:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试上载我的代码,该代码使用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应用此条件格式吗

谢谢


Tags: 文件代码inidformatpandasmy格式

热门问题