Class PropertiesService
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
พร็อพเพอร์ตี้บริการ
อนุญาตให้สคริปต์จัดเก็บข้อมูลทั่วไปในคู่คีย์-ค่าที่มีขอบเขตเป็นสคริปต์เดียว ผู้ใช้สคริปต์รายเดียว หรือเอกสารเดียวที่ใช้ส่วนเสริม คุณจะแชร์พร็อพเพอร์ตี้ระหว่างสคริปต์ไม่ได้
ดูข้อมูลเพิ่มเติมเกี่ยวกับกรณีที่ควรใช้พร็อพเพอร์ตี้แต่ละประเภทได้ที่คู่มือบริการพร็อพเพอร์ตี้
// Sets three properties of different types.
const documentProperties = PropertiesService.getDocumentProperties();
const scriptProperties = PropertiesService.getScriptProperties();
const userProperties = PropertiesService.getUserProperties();
documentProperties.setProperty('DAYS_TO_FETCH', '5');
scriptProperties.setProperty(
'SERVER_URL',
'http://www.example.com/MyWeatherService/',
);
userProperties.setProperty('DISPLAY_UNITS', 'metric');
เอกสารประกอบโดยละเอียด
getDocumentProperties()
รับที่เก็บพร็อพเพอร์ตี้ (สำหรับสคริปต์นี้เท่านั้น) ที่ผู้ใช้ทุกคนเข้าถึงได้ภายในเอกสาร สเปรดชีต หรือแบบฟอร์มที่เปิดอยู่ ตัวเลือกนี้จะใช้ได้ก็ต่อเมื่อสคริปต์ได้รับการเผยแพร่และใช้งานเป็นส่วนเสริม หรือเชื่อมโยงกับประเภทไฟล์ Google เมื่อพร็อพเพอร์ตี้เอกสารไม่พร้อมใช้งาน วิธีการนี้จะแสดงผลเป็น null
พร็อพเพอร์ตี้เอกสารที่สร้างโดยสคริปต์จะเข้าถึงไม่ได้นอกสคริปต์นั้น แม้ว่าสคริปต์อื่นๆ จะเข้าถึงเอกสารเดียวกันก็ตาม
รีเทิร์น
Properties
— พื้นที่เก็บข้อมูลพร็อพเพอร์ตี้สำหรับสคริปต์นี้เท่านั้นที่ผู้ใช้เอกสารปัจจุบันทุกคนเข้าถึงได้ หรือ null
หากสคริปต์ไม่ใช่ส่วนเสริมหรือเชื่อมโยงกับไฟล์ Google Workspace
getScriptProperties()
รับที่เก็บพร็อพเพอร์ตี้ที่ผู้ใช้ทุกคนเข้าถึงได้ แต่ภายในสคริปต์นี้เท่านั้น
รีเทิร์น
Properties
— พื้นที่เก็บข้อมูลพร็อพเพอร์ตี้ที่ผู้ใช้สคริปต์ทุกคนเข้าถึงได้
getUserProperties()
รับที่เก็บพร็อพเพอร์ตี้ที่มีเพียงผู้ใช้ปัจจุบันเท่านั้นที่เข้าถึงได้ และภายในสคริปต์นี้เท่านั้น
รีเทิร์น
Properties
— พื้นที่เก็บข้อมูลพร็อพเพอร์ตี้ที่มีเพียงผู้ใช้ปัจจุบันของสคริปต์เท่านั้นที่เข้าถึงได้
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-26 UTC
[null,null,["อัปเดตล่าสุด 2025-07-26 UTC"],[[["\u003cp\u003eThe Properties Service lets Apps Script store simple data as key-value pairs, with different scopes for scripts, users, and documents.\u003c/p\u003e\n"],["\u003cp\u003eIt offers three methods to access properties: \u003ccode\u003egetDocumentProperties()\u003c/code\u003e, \u003ccode\u003egetScriptProperties()\u003c/code\u003e, and \u003ccode\u003egetUserProperties()\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003egetDocumentProperties()\u003c/code\u003e provides property storage accessible to all users within a specific document, spreadsheet, or form where the script is running.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003egetScriptProperties()\u003c/code\u003e allows storing properties accessible to all users, but only within the context of the current script.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003egetUserProperties()\u003c/code\u003e provides a property store specific to the current user and accessible only within the current script.\u003c/p\u003e\n"]]],["The `PropertiesService` stores data in key-value pairs, accessible via `getDocumentProperties`, `getScriptProperties`, and `getUserProperties`. `getDocumentProperties` stores data within a specific document, accessible to all users. `getScriptProperties` stores data within a script, accessible to all users. `getUserProperties` stores data for a single user within a script. The example code demonstrates setting properties using each method: `setProperty`. Each method returns a `Properties` object, which is a property store.\n"],null,["# Class PropertiesService\n\nPropertiesService\n\nAllows scripts to store simple data in key-value pairs scoped to one script, one user of a\nscript, or one document in which an add-on is used. Properties cannot be shared between scripts.\nFor more information about when to use each type of property, see the [guide to the Properties service](/apps-script/guides/properties).\n\n```javascript\n// Sets three properties of different types.\nconst documentProperties = PropertiesService.getDocumentProperties();\nconst scriptProperties = PropertiesService.getScriptProperties();\nconst userProperties = PropertiesService.getUserProperties();\n\ndocumentProperties.setProperty('DAYS_TO_FETCH', '5');\nscriptProperties.setProperty(\n 'SERVER_URL',\n 'http://www.example.com/MyWeatherService/',\n);\nuserProperties.setProperty('DISPLAY_UNITS', 'metric');\n``` \n\n### Methods\n\n| Method | Return type | Brief description |\n|-----------------------------------------------------|------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------|\n| [getDocumentProperties()](#getDocumentProperties()) | [Properties](/apps-script/reference/properties/properties) | Gets a property store (for this script only) that all users can access within the open document, spreadsheet, or form. |\n| [getScriptProperties()](#getScriptProperties()) | [Properties](/apps-script/reference/properties/properties) | Gets a property store that all users can access, but only within this script. |\n| [getUserProperties()](#getUserProperties()) | [Properties](/apps-script/reference/properties/properties) | Gets a property store that only the current user can access, and only within this script. |\n\nDetailed documentation\n----------------------\n\n### `get``Document``Properties()`\n\nGets a property store (for this script only) that all users can access within the open\ndocument, spreadsheet, or form. It is only available if the script is published and executing\nas an add-on or if it is [bound](https://developers.google.com/apps-script/scripts_containers) to a Google file\ntype. When document properties are not available this method returns `null`. Document\nproperties created by a script are not accessible outside that script, even by other scripts\naccessing the same document.\n\n#### Return\n\n\n[Properties](/apps-script/reference/properties/properties) --- a property store for this script only that all users of the current document can\naccess, or `null` if the script is not either an add-on or bound to a Google\nWorkspace file\n\n*** ** * ** ***\n\n### `get``Script``Properties()`\n\nGets a property store that all users can access, but only within this script.\n\n#### Return\n\n\n[Properties](/apps-script/reference/properties/properties) --- a property store that all users of the script can access\n\n*** ** * ** ***\n\n### `get``User``Properties()`\n\nGets a property store that only the current user can access, and only within this script.\n\n#### Return\n\n\n[Properties](/apps-script/reference/properties/properties) --- a property store that only the current user of the script can access"]]