python - Python - 条件格式谷歌表格 - '电子表格'对象没有属性'add_format'
问题描述
我正在尝试上传我的代码,该代码使用谷歌表格文件上的熊猫数据框值将条件格式应用于 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 install --upgrade https://github.com/nithinmurali/pygsheets/archive/staging.zip
推荐阅读
- angular - mfp中范围元素中的安全检查有什么关系?
- zend-framework - 列不能为空,但已填充
- javascript - 调用绘图函数次数过多时的 HTML 画布限制?
- reactjs - 将 React-Redux 与 Microsoft Fluid 框架集成
- sql-server - 在供应商的链接服务器数据库表上获取插入的行(无法创建触发器)
- visual-studio - 在 Visual Studio 中运行将 exe 作为预构建步骤运行的 PowerShell 脚本
- laravel - 加入频道时 Laravel 回显发送数据
- javascript - 使用 React JS 应用程序在 Mysql 数据库中编辑和保存数据
- python - 带有可选字段的非常嵌套的 JSON 到 pandas 数据框中
- python - 带有字母输入的凯撒密码 python