# range.setNumberFormat()

{% hint style="info" %}
此指令主要是用來設定「儲存格<mark style="color:yellow;">**值的格式**</mark>」(數字、文字、日期等)，但指令名稱取得實在很糟糕。
{% endhint %}

{% tabs %}
{% tab title="💈範例" %}

```javascript
// text
range.setNumberFormat("@");

// date format
range.setNumberFormat("M/d/yy");

// Money format
range.setNumberFormat("$#,##0.00;$(#,##0.00)");
```

{% endtab %}

{% tab title="📘 手冊" %}

* [Date and Number Formats](https://developers.google.com/sheets/api/guides/formats) ⭐️⭐️

* [Format numbers in a spreadsheet](https://support.google.com/docs/answer/56470) ⭐️

* [](https://lochiwei.gitbook.io/web/appendix/gas/classes/range "mention") ⟩&#x20;
  * [getNumberFormat()](https://developers.google.com/apps-script/reference/spreadsheet/range?hl=en#getnumberformat)
  * [setNumberFormat()](https://developers.google.com/apps-script/reference/spreadsheet/range#setnumberformatnumberformat)

* common <mark style="color:yellow;">**syntax characters**</mark> for <mark style="color:purple;">**custom number format**</mark>:

<table><thead><tr><th width="243">Character</th><th>Description</th></tr></thead><tbody><tr><td>0</td><td>A digit in the number. An insignificant 0 will appear in the results.</td></tr><tr><td>#</td><td>A digit in the number. An insignificant 0 will not appear in the results.</td></tr><tr><td>?</td><td>A digit in the number. An insignificant 0 will appear as a space in the results.</td></tr><tr><td>$</td><td>Formats numbers as a dollar value.</td></tr><tr><td>.(period)</td><td>Formats numbers with a decimal point.</td></tr><tr><td>,(comma)</td><td>Formats numbers with a thousands separator.</td></tr><tr><td>/</td><td>Formats numbers as a fraction.</td></tr><tr><td>%</td><td>Formats numbers as a percent</td></tr><tr><td>E</td><td>Formats numbers as an exponent.</td></tr><tr><td>"text"</td><td>Adds text to the formula. Insert the desired text within quotations for it to appear.</td></tr><tr><td>@</td><td>Displays text entered into a cell.</td></tr><tr><td>*</td><td>Repeats the following character to fill in the remaining space in the cell.</td></tr><tr><td>_ (underscore)</td><td>Adds a space equal in width to the following character.</td></tr></tbody></table>

<br>
{% endtab %}

{% tab title="🗣 討論" %}

* [Set cell format with google apps script](https://stackoverflow.com/a/38505701/5409815) ⭐️⭐️⭐️
  {% endtab %}

{% tab title="📗 參考" %}

* Chris Black ⟩ [Cell Number Formatting with Google Apps Script](https://www.blackcj.com/blog/2015/05/18/cell-number-formatting-with-google-apps-script/) ⭐️
  {% endtab %}

{% tab title="👥 相關" %}

* [conditionalformatrule](https://lochiwei.gitbook.io/web/appendix/gas/classes/conditionalformatrule "mention") - 設定條件格式。
  {% endtab %}
  {% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lochiwei.gitbook.io/web/appendix/gas/classes/range/number-format.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
