Google Sheets API – Append Request 不起作用

huangapple go评论84阅读模式
英文:

Google Sheets API - Append Request not working

问题

Here's the translated content:

在使用 API v4 向 Google 表格追加数据时遇到一些困难:

参考此链接链接,我尝试在我的 Google App Script 中使用追加方法,但我收到了一个错误消息,这个错误消息看起来没有意义,因为我尝试了每种可能的组合?

代码片段

var request = {
    spreadsheetId: spreadsheetId,
    range: sheetName + "!A:D",
    insertDataOption: "INSERT_ROWS",
    responseDateTimeRenderOption: "SERIAL_NUMBER",
    responseValueRenderOption: "FORMATTED_VALUE",
    valueInputOption: "USER_ENTERED",
    includeValuesInResponse: true,
    resource: {
        range: sheetName + "!A:D",
        majorDimension: "ROWS",
        values: [["2018-01-01", "2", "3", "4"]]
    }
};

Sheets.Spreadsheets.Values.append(request);

错误

> 异常:提供的参数数量无效。只期望 3-4 个

希望有更好的示例和文档可以提供帮助?

提前感谢。

英文:

Having some difficulty with forming the request to append data on a Google Sheet using the API v4:

Referring to this link, I have attempted to use the append method in my Google App Script, but I am getting an error message, which does not make sense, as I have tried every single combination?

Code Snippet

var request = {
    spreadsheetId: spreadsheetId,
    range: sheetName + "!A:D",
    insertDataOption: "INSERT_ROWS",
    responseDateTimeRenderOption: "SERIAL_NUMBER",
    responseValueRenderOption: "FORMATTED_VALUE",
    valueInputOption: "USER_ENTERED",
    includeValuesInResponse: true,
    resource: {
        range: sheetName + "!A:D",
        majorDimension: "ROWS",
        values: [["2018-01-01", "2", "3", "4"]]
    }
};

Sheets.Spreadsheets.Values.append(request);

Error

> Exception: Invalid number of arguments provided. Expected 3-4 only

I wish there were better samples and documentation to help here?

Thanks in Advance

答案1

得分: 1

function appendDataToSheet() {
var spreadsheetId = "表格ID";
var sheetName = "表格名称";
var resource = {
"values": [["2018-01-01", "2", "3", "4"]]
};
var options = {
insertDataOption: "INSERT_ROWS",
responseDateTimeRenderOption: "SERIAL_NUMBER",
responseValueRenderOption: "FORMATTED_VALUE",
valueInputOption: "USER_ENTERED",
includeValuesInResponse: true
}
Sheets.Spreadsheets.Values.append(resource, spreadsheetId, sheetName + "!A:D", options);
}

英文:

Try this:

function appendDataToSheet() {
  var spreadsheetId = "sheetID";
  var sheetName = "sheetName";  
  var resource = {
    "values": [["2018-01-01", "2", "3", "4"]]
  };
  var options = {
    insertDataOption: "INSERT_ROWS",
    responseDateTimeRenderOption: "SERIAL_NUMBER",
    responseValueRenderOption: "FORMATTED_VALUE",
    valueInputOption: "USER_ENTERED",
    includeValuesInResponse: true
    }
  Sheets.Spreadsheets.Values.append(resource, spreadsheetId, sheetName + "!A:D", options);
}

huangapple
  • 本文由 发表于 2023年6月11日 22:03:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/76450843.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定