使用 Gspread 格式的渐变标记
Gradient markup with Gspread Formatting
我正在使用 Gspread 格式为 Google 表格中的单元格设置背景颜色。
现在我想使用 GradientRule 来完成这个:
Conditional formatting with GradientRule
我知道我必须设置“最小点”和“最大点”,但我不确定如何设置。
这是我目前得到的:
def color():
spr = client.open("Kleurtjes")
sheet = spr.worksheet("Tab3")
rule = ConditionalFormatRule(
ranges=[GridRange.from_a1_range('A1:A10', sheet)],
GradientRule=GradientRule(
minpoint(format=CellFormat(backgroundColor=Color(255,255,255)), type='number'),
maxpoint(format=CellFormat(backgroundColor=Color(0,128,0)), type='number')
)
)
rules = get_conditional_format_rules(sheet)
rules.append(rule)
rules.save()
你能帮帮我吗?
非常感谢!
我相信你的目标如下。
你想实现如下情况。 (图片来自您的问题。)
修改点:
- 在here and here可以看到
GradientRule()
和InterpolationPoint()
的脚本。
- 在
ConditionalFormatRule()
,好像用到了SheetsAPI中的batchUpdate方法的AddConditionalFormatRuleRequest。在这种情况下,颜色需要设置为0
到1
。请注意这一点。
当以上几点反映到你的脚本中,就会变成下面这样。
修改后的脚本:
请按如下方式修改您的脚本。
从:
rule = ConditionalFormatRule(
ranges=[GridRange.from_a1_range('A1:A10', sheet)],
GradientRule=GradientRule(
minpoint(format=CellFormat(backgroundColor=Color(255,255,255)), type='number'),
maxpoint(format=CellFormat(backgroundColor=Color(0,128,0)), type='number')
)
)
到:
rule = ConditionalFormatRule(
ranges=[GridRange.from_a1_range('A1:A10', sheet)],
gradientRule=GradientRule(
maxpoint=InterpolationPoint(color=Color(1, 1, 1), type='MAX'),
minpoint=InterpolationPoint(color=Color(0, 128 / 255, 0), type='MIN')
)
)
注:
- 在此修改中,假设您已经能够通过使用带有 gspread 和 gspread_formatting 的表格 API 来获取和放置 Google 电子表格的值。请注意这一点。
- 当你想要实现图像上方的颜色时,例如,
minpoint=InterpolationPoint(color=Color(0.34117648, 0.73333335, 0.5411765), type='MIN')
如何?
参考文献:
我正在使用 Gspread 格式为 Google 表格中的单元格设置背景颜色。 现在我想使用 GradientRule 来完成这个:
Conditional formatting with GradientRule
我知道我必须设置“最小点”和“最大点”,但我不确定如何设置。
这是我目前得到的:
def color():
spr = client.open("Kleurtjes")
sheet = spr.worksheet("Tab3")
rule = ConditionalFormatRule(
ranges=[GridRange.from_a1_range('A1:A10', sheet)],
GradientRule=GradientRule(
minpoint(format=CellFormat(backgroundColor=Color(255,255,255)), type='number'),
maxpoint(format=CellFormat(backgroundColor=Color(0,128,0)), type='number')
)
)
rules = get_conditional_format_rules(sheet)
rules.append(rule)
rules.save()
你能帮帮我吗?
非常感谢!
我相信你的目标如下。
你想实现如下情况。 (图片来自您的问题。)
修改点:
- 在here and here可以看到
GradientRule()
和InterpolationPoint()
的脚本。 - 在
ConditionalFormatRule()
,好像用到了SheetsAPI中的batchUpdate方法的AddConditionalFormatRuleRequest。在这种情况下,颜色需要设置为0
到1
。请注意这一点。
当以上几点反映到你的脚本中,就会变成下面这样。
修改后的脚本:
请按如下方式修改您的脚本。
从:rule = ConditionalFormatRule(
ranges=[GridRange.from_a1_range('A1:A10', sheet)],
GradientRule=GradientRule(
minpoint(format=CellFormat(backgroundColor=Color(255,255,255)), type='number'),
maxpoint(format=CellFormat(backgroundColor=Color(0,128,0)), type='number')
)
)
到:
rule = ConditionalFormatRule(
ranges=[GridRange.from_a1_range('A1:A10', sheet)],
gradientRule=GradientRule(
maxpoint=InterpolationPoint(color=Color(1, 1, 1), type='MAX'),
minpoint=InterpolationPoint(color=Color(0, 128 / 255, 0), type='MIN')
)
)
注:
- 在此修改中,假设您已经能够通过使用带有 gspread 和 gspread_formatting 的表格 API 来获取和放置 Google 电子表格的值。请注意这一点。
- 当你想要实现图像上方的颜色时,例如,
minpoint=InterpolationPoint(color=Color(0.34117648, 0.73333335, 0.5411765), type='MIN')
如何?