python - 如何通过 Python API 为 Google 电子表格中的单元格背景着色
问题描述
from pprint import pprint
scope = ["https://spreadsheets.google.com/feeds",'https://www.googleapis.com/auth/spreadsheets',"https://www.googleapis.com/auth/drive.file","https://www.googleapis.com/auth/drive"]
creds = ServiceAccountCredentials.from_json_keyfile_name("creds.json", scope)
client = gspread.authorize(creds)
for i in range (1,8):
sheet = client.open("haniftest").sheet1 # Open the spreadhseet
cell = sheet.cell(i,1).value
print(cell)
sheet2 = client.open("haniftest").worksheet('Sheet2')
sheet2.update_cell(i,1,cell)
我想知道如何通过 Python API 为 Google 电子表格中的单元格背景着色
解决方案
要格式化特定单元格,您需要使用 format 函数更新工作表元素:
worksheet.format('A1:A1', { "backgroundColor": {"red": xx, "green": yy, "blue": zz}
您还可以查看 gspread-formatting 模块。
一些链接:
推荐阅读
- python - 从python中的函数返回值时,它返回为空
- python - 手写数字图像分类的特征提取
- android - 如何使用两个 List 制作 ExpandableListView
- javascript - 在 ng2-date-picker 上禁用周末
- javascript - 如何使用reactjs在点击表格行时打开url
- sql-server - 如何将表名列表传递给 SQL Server 中的存储过程?
- python - 比较 Hive 中表的两个分区
- python-3.x - 带有 apache 身份验证的 REST-API python 请求
- python - 无法加载动态库“cudart64_110.dll”;dlerror: 未找到 cudart64_110.dll
- python - 用于成对比较的弗里德曼检验统计量产生 NaN