我试图用谷歌单张把我的头染成紫色,但是GSpread textFormat似乎没有恢复正确的颜色。
我看过GSpread文档,几乎没有什么关于颜色代码应该是什么格式的,所以我只是假设RGB应该是这样的。
还查看了使用RGB的。
fmt = CellFormat(textFormat=textFormat(bold=True, foregroundColor=color(112, 48, 160), fontSize=24),)
format_cell_range(worksheet, 'B1:B1', fmt)标题的颜色应与以下RGB代码相同:(112、48、160)
而不是这个:(144,208,96)
发布于 2019-07-24 22:27:45
112, 48, 160的颜色,即RGB。
gspread-formatting来实现这一点。如果我的理解是正确的,那么这个答案呢?
准备:
在使用此修改脚本之前,请按以下方式安装gspread-formatting。如果您已经安装了它,请跳过本节。
$ pip install gspread-formatting修改脚本:
请设置spreadsheetId和sheetName。
import gspread_formatting as gsf # <--- Also please add this to your script.
spreadsheetId = "###"
sheetName = "Sheet1"
client = gspread.authorize(credentials)
ss = client.open_by_key(spreadsheetId)
worksheet = ss.worksheet(sheetName)
fmt = gsf.cellFormat(
textFormat=gsf.textFormat(
bold=True, foregroundColor=gsf.color(112, 48, 160), fontSize=24)
)
gsf.format_cell_range(worksheet, 'B1:B1', fmt)参考文献:
如果这对你的处境没什么用,我很抱歉。
发布于 2022-02-15 05:20:05
Sheets希望RGB (和alpha)值在(0,1)范围内;将每个典型值除以255.0,您将看到预期的结果。
就作者而言,获取所需的rgb值的解决方案是:
fmt = CellFormat(textFormat=textFormat(bold=True, foregroundColor=color(112/250, 48/250, 160/250), fontSize=24),)
format_cell_range(worksheet, 'B1:B1', fmt)在https://developers.google.com/sheets/api/samples/formatting中有一些说明性的例子
资料来源: https://github.com/robin900/gspread-formatting/issues/7
https://stackoverflow.com/questions/57182963
复制相似问题