๐Ÿ’พ sheet.setValues()

โฌ†๏ธ ๅ…งๅซๆ–ผ๏ผš app.sheet.prototype

/**
 * write 2D data into sheet.
 * @example
 * sheet.__proto__ = app.sheetPrototype
 * sheet.setValues(data)
 */
app.sheetPrototype = {

  // ๐Ÿ”ธ sheet.setValues(data)
  setValues(data, row=1, col=1){

    if(!data || data.length === 0 || !data[0] || data[0].length === 0) 
      throw new Error(`โ›”๏ธ app.sheetPrototype.setValues(): data ๆ˜ฏ็ฉบ็š„๏ผŒ็„กๆณ•ๅฏซๅ…ฅ่ฉฆ็ฎ—่กจโ—๏ธ`);

    // ่ณ‡ๆ–™่กจ็š„ใ€Œๅˆ—ๆ•ธใ€่ˆ‡ใ€Œๆฌ„ๆ•ธใ€
    let rows = data.length;
    let cols = data[0].length;

    // ๅฏซๅ…ฅ้ ้ข
    this
      .getRange(row, col, rows, cols)
      .setValues(data);

    return this;   // for chaining
  },
};

Last updated