我正在尝试格式化 Google 表格。这是基于 Ruby 的 Google API 文档、条件格式和 Ruby 文档(非常差)的代码。
- https://developers.google.com/sheets/api/guides/batchupdate
- https://developers.google.com/sheets/api/samples/conditional-formatting
- https://www.rubydoc.info/github/google/google-api-ruby-client/Google/Apis/SheetsV4/Sheet#conditional_formats-instance_method
到目前为止,我还没有找到任何关于如何使代码适应 Ruby 的完整文档。
终端返回:
`check_status': badRequest: Invalid requests[0]: No request set. (Google::Apis::ClientError)
您知道如何使此代码工作吗?
requests.push({
add_conditional_formats: {
rule: {
ranges: [
{
sheet_id: 0, start_column_index: 9, end_column_index: 100,
}
],
gradient_rule: {
minpoint: {
color: {
green: 0.2,
red: 0.8
},
type: "MIN"
},
maspoint: {
color: {
green: 0.9
},
type: "MAX"
},
}
},
index: 0
},
add_conditional_formats: {
rule: {
ranges: [
{
sheet_id: 0, start_column_index: 9, end_column_index: 100,
}
],
gradient_rule: {
minpoint: {
color: {
green: 0.2,
red: 0.8
},
type: "NUMBER",
value: 0
},
maspoint: {
color: {
green: 0.9
},
type: "NUMBER",
value: 256
},
}
},
index: 1
}
})
body = {requests: requests}
result = service.batch_update_spreadsheet(spreadsheet_id, body, {})
最佳答案
这个修改怎么样?此修改后的脚本假设您的访问 token 可用于更新电子表格。
修改点:
add_conditional_format_rule
是一个请求。因此,在您的情况下,requests
数组需要为 2 个元素,因为您在请求中使用了 2 个add_conditional_format_rule
。maspoint
是maxpoint
。add_conditional_formats
是add_conditional_format_rule
。sheet_id
的值为字符串。gradient_rule
的value
值为字符串。
修改后的脚本:
requests = []
requests.push({
add_conditional_format_rule: {
rule: {
ranges: [
{
sheet_id: "0", start_column_index: 9, end_column_index: 100,
}
],
gradient_rule: {
minpoint: {
color: {
green: 0.2,
red: 0.8
},
type: "MIN"
},
maxpoint: {
color: {
green: 0.9
},
type: "MAX"
},
}
},
index: 0
}
},{
add_conditional_format_rule: {
rule: {
ranges: [
{
sheet_id: "0", start_column_index: 9, end_column_index: 100,
}
],
gradient_rule: {
minpoint: {
color: {
green: 0.2,
red: 0.8
},
type: "NUMBER",
value: "0"
},
maxpoint: {
color: {
green: 0.9
},
type: "NUMBER",
value: "256"
},
}
},
index: 1
}
})
body = {requests: requests}
result = service.batch_update_spreadsheet(spreadsheet_id, body, {})
引用:
如果这不是您想要的,我很抱歉。
关于Ruby 条件格式 get badRequest: 无效请求[0]: 未设置请求。 (谷歌::Apis::客户端错误),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50667671/