英文:
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);
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论