如何在Google Sheets Node.js脚本中循环值?

时间:2019-06-25 14:02:41

标签: node.js google-sheets google-sheets-api

执行此脚本后,我需要在下一行中插入值。行之间的差异是13。

我将如何循环播放此脚本,以便在执行后,值显示在下一行?

// Google Sheets API
const GoogleSpreadsheet = require('google-spreadsheet');
const {promisify} = require('util');
const creds = require('./client_secret.json');
var counter = 0; // Used to debug cellnumber association

    // Define Spreadhseet Scope
    const cells = await promisify(sheet.getCells)({
        'min-row': 1,
        'max-row': 106,
        'min-col': 1,
        'max-col': 13,
        'return-empty': true
    });

    // Get a list of all the cells and relate them to a counter for assigning variables
    for(const cell of cells){
        counter++;
        console.log(`${counter-1} -- ${cell.row}, ${cell.col}: ${cell.value}`);
    }

    /* Assign all variables to related spreadsheet cell */
    cells[17].value = value + '%';
    cells[17].save();
    cells[18].value = value + '%';
    cells[18].save();
    cells[19].value =  value+ '%';
    cells[19].save();
    cells[20].value =  value+ '%' ;
    cells[20].save();
    cells[21].value = value+ '%';
    cells[21].save();
    cells[22].value =  value + '%';
    cells[22].save();


}

sendToGoogleSpreadsheet();

0 个答案:

没有答案