使用for循环增量打印数组项
我试图让一行注释掉的块在rowEcho上重复,具体取决于batchLength。用注释掉的“数组”替换整个函数按预期工作。这一切都发生在数据:[]对象中,我试图将值推送到谷歌工作表,以更新每行中的单元格,因为在响应数组中找到了记录。
感谢您的回复,但这些选项都没有按预期工作。我发布了更完整的代码以提供更好的范围,因为您可以看到我正在使用带有工作表API的preadsheets.values.batchUpdate请求尝试推送新数组但是使用batchUpdate方法必须按顺序知道整个新数据范围要覆盖,似乎没有办法更新列中的所有单元格,除非你有范围结束,因此我的下面尝试只要表格中有行就生成具有新数据的每个数组。肮脏我知道..
function changeSentValue(auth) {
var x = 0;
for (var x = 0; x < rows.length; x++) {
// put update spreadt sheet here
console.log('updating to sent items..');
const sheets = google.sheets({ version: 'v4', auth });
sheets.spreadsheets.values.batchUpdate(request, function(err, response) {
//var rows = response.data.values;
if (err) {
console.error(err);
return;
}
///here
});
var request = {
spreadsheetId: 'xxxxxxxxxxxxxxxxxxxxx',
resource: {
valueInputOption: 'RAW',
includeValuesInResponse: true,
responseValueRenderOption: "UNFORMATTED_VALUE",
// The new values to apply to the spreadsheet.
data: [
{
range: 'Sheet1!A2',
majorDimension: "ROWS",
// values: [[5],[2],[5]]
values: [
function getLength () {
var batchRows = response.data.values;
var batchLength = 13/* batchRows.length */;
var rowEcho = '[null,null,null,null,null,null,null,null,null,null,\"not\"],'; //col 11
var y
for (y = 0; y < batchLength; y ++) {
//write(rowEcho);
//console.log(rowEcho(y));
//these both dont work as expected
}
}
/* [null,null,null,null,null,null,null,null,null,null,"notSent"],
[null,null,null,null,null,null,null,null,null,null,"notSent"],
[null,null,null,null,null,null,null,null,null,null,"notSent"],
[null,null,null,null,null,null,null,null,null,null,"notSent"],
[null,null,null,null,null,null,null,null,null,null,"notSent"],
[null,null,null,null,null,null,null,null,null,null,"notSent"],
[null,null,null,null,null,null,null,null,null,null,"notSent"],
[null,null,null,null,null,null,null,null,null,null,"notSent"],
[null,null,null,null,null,null,null,null,null,null,"notSent"],
[null,null,null,null,null,null,null,null,null,null,"notSent"],
[null,null,null,null,null,null,null,null,null,null,"notSent"],
*/
]
}
], // TODO: Update placeholder value.
// TODO: Add desired properties to the request body.
},
auth: auth,
}
}
}
回答如下:
function getLength() {
var batchLength = 8/* batchRows.length */;
var rowEcho = '[null,null,null,null,null,null,null,null,null,null,\"not\"],'; //col 11
var y
for (y = 0; y < batchLength; y++) {
//You forgot to print it
console.log(rowEcho);
}
}