【发布时间】:2020-04-09 15:02:04
【问题描述】:
作为开发人员,我使用此端点:https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/batchUpdate
并要求: https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/request#AppendCellsRequest 插入具有值的新行。
我有一些列格式样式的电子表格:背景颜色/字体重量/文本换行/数据验证。
问题,当我使用这样的请求时:
curl --request POST \
'https://sheets.googleapis.com/v4/spreadsheets/1SoDx8YRyiKF9vKfa_2w0xc7DTNIlQoLC6hBq1SCJEJY:batchUpdate?key=[YOUR_API_KEY]' \
--header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{"requests":[{"appendCells":{"sheetId":0,"fields":"*","rows":[{"values":[{"userEnteredValue":{"stringValue":"TEST STRING VALUE long"}},{"userEnteredValue":{"stringValue":"TEST TEXT LONG"}}]}]}}]}' \
--compressed
我看到文本换行和数据验证样式被忽略了:
这里我只使用的关键点:'userEnteredValue' 字段来提供值。
根据文档: https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/cells#CellData 我可以使用'userEnteredFormat'/'dataValidation',但是“写入时,新格式将与现有格式合并。”我发现再次获取和发布这些样式格式非常复杂。
我的问题 - 有没有办法尽可能简单地使用 AppendCellsRequest 发布 CellData 并保留现有的列样式?
【问题讨论】:
-
我为我糟糕的英语水平道歉。不幸的是,我无法从您的图片中了解
I see that text-wrap and data-validation styles are ignored:。可以问一下具体情况吗? -
嗨!更新了我的描述。如您所见,第一列缺少验证“警告”,并且两列都忽略了文本换行
-
感谢您的回复和补充信息。根据您的附加信息,我提出了一个修改点作为答案。你能确认一下吗?如果我误解了您的问题并且这不是您想要的结果,我深表歉意。