用颜色解析谷歌表格

问题描述 投票:0回答:1

有没有什么方法可以在不使用谷歌API的情况下从谷歌表格中的单元格中读取颜色? API 有限制,我的工作表大小约为 200x400,解析需要数年时间...

为了读取和解析值,我在 url 中使用了

/export
,默认导出为 xlsx 格式。但由于未知原因,这种方式并不能保留单元格颜色。

/export?format=ods
工作正常,具有所有必要的颜色,但我找不到任何有关从Python中的ods表获取单元格颜色的信息...

Google 查询,例如:

/gviz/tq?tqx=out:html
没有给出任何颜色。

python google-sheets google-api-python-client
1个回答
0
投票

解决方案是直接使用google API。

这里开始,有一种方法可以通过向下访问属性树来请求特定值

# as always create service instance
service = build('sheets', 'v4', credentials=CREDS)

# now request any required properties according to API
fields_cells = "sheets(data(rowData(values(userEnteredValue,userEnteredFormat/backgroundColor))))"
request = service.spreadsheets().get(
    spreadsheetId=sheet_id,
    ranges=range_name,
    fields=fields_cells,
)
resp = request.execute()

只需一次请求即可返回指定范围内的请求值

© www.soinside.com 2019 - 2024. All rights reserved.