Ruby条件格式化得到badRequest:无效请求[0]:没有设置请求。 (谷歌::蜜蜂:: ClientError)

时间:2018-06-03 14:51:45

标签: ruby google-sheets gs-conditional-formatting

我正在尝试格式化Google表格。这是基于Ruby的Google API文档,条件格式和Ruby Doc(非常差)的代码。

到目前为止,我没有找到关于如何使代码适应Ruby的任何完整文档。

终端返回:

  `check_status&#39 ;: badRequest:无效请求[0]:没有设置请求。 (谷歌::蜜蜂:: 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, {})

1 个答案:

答案 0 :(得分:2)

这次修改怎么样?此修改后的脚本假设您的访问令牌可用于更新电子表格。

修改要点:

  • add_conditional_format_rule是一个请求。因此,在您的情况下,requests数组必须是2个元素,因为您在请求中使用了2 add_conditional_format_rule
  • maspointmaxpoint
  • add_conditional_formatsadd_conditional_format_rule
  • sheet_id的值为字符串。
  • value gradient_rule的值为字符串。

修改后的脚本:

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, {})

参考:

如果这不是你想要的,我很抱歉。

相关问题