Class NamedRange
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
Range ที่มีชื่อ
สร้าง เข้าถึง และแก้ไขช่วงที่ตั้งชื่อในสเปรดชีต ช่วงที่ตั้งชื่อแล้วคือช่วงที่มีอลิแอสสตริงที่เชื่อมโยง โดยดูและแก้ไขได้ผ่าน UI ของชีตในเมนูข้อมูล > ช่วงนี้ที่มีชื่อ...
เอกสารประกอบโดยละเอียด
getName()
รับชื่อของช่วงที่มีชื่อนี้
รีเทิร์น
String
— ชื่อของช่วงที่มีชื่อนี้
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getRange()
รับช่วงที่อ้างอิงโดยช่วงที่มีชื่อนี้
รีเทิร์น
Range
— ช่วงของสเปรดชีตที่เชื่อมโยงกับช่วงที่มีชื่อนี้
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
remove()
ลบช่วงที่มีชื่อนี้
// The code below deletes all the named ranges in the spreadsheet.
const namedRanges = SpreadsheetApp.getActive().getNamedRanges();
for (let i = 0; i < namedRanges.length; i++) {
namedRanges[i].remove();
}
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setName(name)
ตั้งค่า/อัปเดตชื่อของช่วงที่มีชื่อ
// The code below updates the name for the first named range.
const namedRanges = SpreadsheetApp.getActiveSpreadsheet().getNamedRanges();
if (namedRanges.length > 1) {
namedRanges[0].setName('UpdatedNamedRange');
}
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
name | String | ชื่อใหม่ของช่วงที่มีชื่อ |
รีเทิร์น
NamedRange
— ช่วงที่ชื่อได้รับการตั้งค่าโดยการเรียกใช้
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setRange(range)
ตั้งค่า/อัปเดตช่วงสําหรับช่วงที่มีชื่อนี้
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
range | Range | ช่วงของสเปรดชีตที่จะเชื่อมโยงกับช่วงที่มีชื่อนี้ |
รีเทิร์น
NamedRange
— ช่วงที่มีชื่อซึ่งตั้งค่าช่วงสเปรดชีตไว้
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-26 UTC
[null,null,["อัปเดตล่าสุด 2025-07-26 UTC"],[[["\u003cp\u003eNamed ranges provide string aliases for cell ranges within a spreadsheet, enhancing readability and simplifying formulas.\u003c/p\u003e\n"],["\u003cp\u003eYou can manage named ranges through the Sheets UI under "Data > Named ranges..." or programmatically using Apps Script methods.\u003c/p\u003e\n"],["\u003cp\u003eApps Script offers methods to create, access, modify, and delete named ranges, including \u003ccode\u003egetName()\u003c/code\u003e, \u003ccode\u003egetRange()\u003c/code\u003e, \u003ccode\u003eremove()\u003c/code\u003e, \u003ccode\u003esetName()\u003c/code\u003e, and \u003ccode\u003esetRange()\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThese methods enable you to retrieve and update the name and range associated with a named range, as well as delete it entirely.\u003c/p\u003e\n"],["\u003cp\u003eAuthorization is required to utilize these methods, necessitating specific scopes like \u003ccode\u003ehttps://www.googleapis.com/auth/spreadsheets\u003c/code\u003e.\u003c/p\u003e\n"]]],["Named ranges in spreadsheets can be managed using provided methods. You can retrieve a named range's name using `getName()`, or its associated range using `getRange()`. To modify, use `setName(name)` to change the named range's alias and `setRange(range)` to assign it a new range. To delete the range use `remove()`. These actions require spreadsheet authorization scopes. The UI location is in **Data \u003e Named ranges...** menu.\n"],null,["# Class NamedRange\n\nNamedRange\n\nCreate, access and modify named ranges in a spreadsheet. Named ranges are ranges that have\nassociated string aliases. They can be viewed and edited via the Sheets UI under the **Data \\\u003e\nNamed ranges...** menu. \n\n### Methods\n\n| Method | Return type | Brief description |\n|-------------------------------------|---------------------------------------------------|------------------------------------------------|\n| [getName()](#getName()) | `String` | Gets the name of this named range. |\n| [getRange()](#getRange()) | [Range](/apps-script/reference/spreadsheet/range) | Gets the range referenced by this named range. |\n| [remove()](#remove()) | `void` | Deletes this named range. |\n| [setName(name)](#setName(String)) | [NamedRange](#) | Sets/updates the name of the named range. |\n| [setRange(range)](#setRange(Range)) | [NamedRange](#) | Sets/updates the range for this named range. |\n\nDetailed documentation\n----------------------\n\n### `get``Name()`\n\nGets the name of this named range.\n\n#### Return\n\n\n`String` --- the name of this named range\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/spreadsheets.currentonly`\n- `https://www.googleapis.com/auth/spreadsheets`\n\n*** ** * ** ***\n\n### `get``Range()`\n\nGets the range referenced by this named range.\n\n#### Return\n\n\n[Range](/apps-script/reference/spreadsheet/range) --- the spreadsheet range that is associated with this named range\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/spreadsheets.currentonly`\n- `https://www.googleapis.com/auth/spreadsheets`\n\n*** ** * ** ***\n\n### `remove()`\n\nDeletes this named range.\n\n```javascript\n// The code below deletes all the named ranges in the spreadsheet.\nconst namedRanges = SpreadsheetApp.getActive().getNamedRanges();\nfor (let i = 0; i \u003c namedRanges.length; i++) {\n namedRanges[i].remove();\n}\n```\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/spreadsheets.currentonly`\n- `https://www.googleapis.com/auth/spreadsheets`\n\n*** ** * ** ***\n\n### `set``Name(name)`\n\nSets/updates the name of the named range.\n\n```javascript\n// The code below updates the name for the first named range.\nconst namedRanges = SpreadsheetApp.getActiveSpreadsheet().getNamedRanges();\nif (namedRanges.length \u003e 1) {\n namedRanges[0].setName('UpdatedNamedRange');\n}\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|--------|----------|----------------------------------|\n| `name` | `String` | The new name of the named range. |\n\n#### Return\n\n\n[NamedRange](#) --- the range whose name was set by the call\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/spreadsheets.currentonly`\n- `https://www.googleapis.com/auth/spreadsheets`\n\n*** ** * ** ***\n\n### `set``Range(range)`\n\nSets/updates the range for this named range.\n\n#### Parameters\n\n| Name | Type | Description |\n|---------|---------------------------------------------------|-----------------------------------------------------------|\n| `range` | [Range](/apps-script/reference/spreadsheet/range) | The spreadsheet range to associate with this named range. |\n\n#### Return\n\n\n[NamedRange](#) --- the named range for which the spreadsheet range was set\n\n#### Authorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/spreadsheets.currentonly`\n- `https://www.googleapis.com/auth/spreadsheets`"]]