> For the complete documentation index, see [llms.txt](https://lochiwei.gitbook.io/web/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lochiwei.gitbook.io/web/appendix/gas/app/prototypes/app.sheet.prototype/sheet.setvalues.md).

# 💾 sheet.setValues()

{% tabs %}
{% tab title="💾 程式" %}
⬆️ 內含於： [app.sheet.prototype](/web/appendix/gas/app/prototypes/app.sheet.prototype.md)

```javascript
/**
 * 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
  },
};
```

{% endtab %}

{% tab title="Second Tab" %}

{% endtab %}
{% endtabs %}
