Google Sheet API问题Golang [英] Google Sheet API issue Golang

查看:91
本文介绍了Google Sheet API问题Golang的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道如何更改一个单元格的值.它在rb变量值上失败.我一直在阅读文档,并在网上运气不佳.

I cant figure out how to change the value of one cell. Its failing on the rb variable values. I've been reading the docs and searching the web with no luck.

// The ID of the spreadsheet to update.
    spreadsheetId := "XXXXX" // TODO: Update placeholder value.

    // The A1 notation of the values to update.
    range2 := "B2" // TODO: Update placeholder value.

    // How the input data should be interpreted.
    valueInputOption := "" // TODO: Update placeholder value.

    rb := &sheets.ValueRange{
        "range":          string,
        "majorDimension": enum(Dimension),
        "values":         []string{"34344",},
    }

    resp, err := sheetsService.Spreadsheets.Values.Update(spreadsheetId, range2, rb).ValueInputOption(valueInputOption).Context(ctx).Do()

推荐答案

我相信您的目标如下.

  • 您要使用带golang的googleapis将值放入Google Spreadsheet.
  • 您已经可以通过Sheets API获取和放置值.
    • 在脚本中,尽管未显示用于授权的脚本,但 sheetsService 可以用于使用Sheets API放置值.
    • You want to put the values to Google Spreadsheet using googleapis with golang.
    • You have already been able to get and put values by using Sheets API.
      • In your script, although you don't show the script for authorizing, sheetsService can be used for putting values using Sheets API.

      为此,这个答案如何?

      • 我认为在您的脚本中,需要修改 valueInputOption rb 和放置值的请求.
        • 例如,请将 USER_ENTERED 放入 valueInputOption .
        • 关于 rb ,我认为 jmaitrehenry的评论是正确的.作为附加的修改点, Values [] [] interface {} .在这种情况下, MajorDimension 使用 ROWS 作为示例.
        • 关于请求,我认为在这种情况下,不需要 Context(ctx).
        • I think that in your script, valueInputOption, rb and the request for putting values are required to be modified.
          • For example, please put USER_ENTERED to valueInputOption.
          • About rb, I think that jmaitrehenry's comment is correct. As additional modification point, Values is [][]interface{}. And in this case, MajorDimension uses ROWS as a sample.
          • About the request, I think that in this case, Context(ctx) is not required.

          当以上几点反映到您的脚本中时,它如下所示.

          When above points are reflected to your script, it becomes as follows.

          在使用此功能之前,请设置电子表格ID.

          Before you use this, please set the Spreadsheet ID.

          spreadsheetId := "###"
          range2 := "b2"
          values := [][]interface{}{[]interface{}{"b2", "c2", "d2"}, []interface{}{"b3", "c3", "d3"}}
          valueInputOption := "USER_ENTERED"
          rb := &sheets.ValueRange{
              MajorDimension: "ROWS",
              Values:         values,
          }
          resp, err := sheetsService.Spreadsheets.Values.Update(spreadsheetId, range2, rb).ValueInputOption(valueInputOption).Do()
          

          • sheetsService 可以用于放置值时,运行脚本时, b2,c2,d2 b3,c3,d3 放在Google电子表格第一个标签中的"B2:D3"单元格中.
            • When sheetsService can be used for putting values, When you run the script, the values of b2, c2, d2 and b3, c3, d3 are put to the cells "B2:D3" in the 1st tab on Google Spreadsheet.
              • 在这种情况下, range2 是a1Notation.例如,当您要将值放入 Sheet2 的工作表名称时,请设置 range2:="Sheet2!b2" .当使用 range2:="b2" 时,该值将放置在Google Spreadsheet的第一个标签上.请注意这一点.
              • 在这种情况下,作为放置值的范围,请设置 https://www.googleapis.com/auth/spreadsheets .
              • In this case, range2 is a1Notation. For example, when you want to put the values to the sheet name of Sheet2, please set range2 := "Sheet2!b2". When range2 := "b2" is used, the value is put to the 1st tab on the Google Spreadsheet. Please be careful this.
              • As the scope for putting values, in this case, please set https://www.googleapis.com/auth/spreadsheets.

              这篇关于Google Sheet API问题Golang的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆