การขยาย Google ชีตด้วยส่วนเสริม
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
Google ชีตคือโซลูชันสเปรดชีตในระบบคลาวด์
ที่มีการทำงานร่วมกันแบบเรียลไทม์และเครื่องมือที่มีประสิทธิภาพในการ
แสดงภาพ ประมวลผล และสื่อสารข้อมูล
คุณสามารถขยายชีตด้วยส่วนเสริมที่สร้างการปรับปรุงเวิร์กโฟลว์ที่กำหนดเอง
สร้างการเชื่อมต่อกับระบบของบุคคลที่สาม และผสานรวมข้อมูลชีต
กับแอปพลิเคชันอื่นๆ ของ Google Workspace (เช่น
Google สไลด์)
คุณดูส่วนเสริมของชีตที่ผู้อื่นสร้างไว้ได้ใน Google Workspace Marketplace
สิ่งที่ทำได้
ตัวอย่างสิ่งที่คุณจะทำได้เมื่อใช้ส่วนเสริมที่ขยาย Google ชีตมีดังนี้
ส่วนเสริมของชีตสร้างขึ้นโดยใช้ Apps Script ดูข้อมูลเพิ่มเติมเกี่ยวกับวิธีเข้าถึง
และจัดการ Google ชีตด้วย Apps Script ได้ที่
การขยาย Google ชีต
โครงสร้างชีต
สเปรดชีต Google ชีตประกอบด้วยชีตอย่างน้อย 1 รายการ ชีตแต่ละแผ่นเป็นตารางกริด 2 มิติของเซลล์ที่สามารถจัดเก็บข้อความ ตัวเลข ลิงก์ หรือค่าอื่นๆ
ได้ กลุ่มของเซลล์ที่อยู่ติดกันอย่างน้อย 1 เซลล์เรียกว่าช่วง
บริการสเปรดชีตของ Apps Script
มีหลายคลาสที่แสดงโครงสร้างขององค์กรในชีต
(เช่น Sheet
และ
Range
) คุณสามารถใช้คลาสเหล่านี้
เพื่ออ่านและแก้ไขข้อมูลและลักษณะการทำงานของชีตได้
ทริกเกอร์
ทริกเกอร์ของ Apps Script ช่วยให้โปรเจ็กต์สคริปต์
เรียกใช้ฟังก์ชันที่ระบุเมื่อมีคุณสมบัติตรงตามเงื่อนไขบางอย่าง เช่น เมื่อมีการเปิด
สเปรดชีตหรือเมื่อมีการติดตั้งส่วนเสริม
ดูข้อมูลเพิ่มเติมเกี่ยวกับทริกเกอร์ที่ใช้กับส่วนเสริมของชีตได้และข้อจำกัดที่ใช้กับการใช้งานได้ที่ทริกเกอร์ส่วนเสริม
ฟังก์ชันที่กำหนดเอง
Google ชีตมี
ฟังก์ชันในตัว
หลายอย่าง เช่น SUM
และ AVERAGE
ที่เรียกใช้ได้จากภายในเซลล์ของ Google ชีต
ส่วนเสริมของชีตสามารถกำหนดฟังก์ชันที่กำหนดเองเพิ่มเติมเพื่อเสริมฟังก์ชันในตัวเหล่านี้ เมื่อผู้ใช้
ติดตั้งส่วนเสริม ฟังก์ชันที่กำหนดเองที่รวมอยู่ในส่วนเสริม
จะพร้อมใช้งานทันที ส่วนเสริมอาจประกอบด้วย
เฉพาะคำจำกัดความของฟังก์ชันที่กำหนดเอง โดยหลักแล้ว คุณจะแชร์คำจำกัดความฟังก์ชันที่กำหนดเองกับผู้อื่นได้โดยการเผยแพร่ส่วนเสริมที่มีคำจำกัดความ
การสร้างฟังก์ชันที่กำหนดเองของส่วนเสริม
ฟังก์ชันที่กำหนดไว้ในโปรเจ็กต์สคริปต์ของส่วนเสริมสามารถใช้เป็นฟังก์ชันที่กำหนดเองได้ เมื่อติดตั้งใช้งานฟังก์ชันและติดตั้งส่วนเสริมแล้ว คุณจะเรียกฟังก์ชันที่กำหนดเองได้เหมือนกับฟังก์ชันชีตในตัวอื่นๆ โดยในเซลล์ชีต ให้ป้อน =
ตามด้วยชื่อฟังก์ชันและพารามิเตอร์ที่จำเป็น หากไม่มีข้อผิดพลาด ระบบจะวางผลลัพธ์ที่ฟังก์ชันแสดงในเซลล์ชีตและล้นไปยังเซลล์ข้างเคียงตามความจำเป็น
เมื่อสร้างฟังก์ชันที่กำหนดเองในส่วนเสริม คุณควรทำตาม
หลักเกณฑ์ทั่วไปสำหรับฟังก์ชันที่กำหนดเอง
นอกจากนี้ ฟังก์ชันที่กำหนดเองซึ่งกำหนดไว้ในส่วนเสริมยังมีข้อควรพิจารณาพิเศษบางประการ ดังนี้
- เมื่อตั้งชื่อฟังก์ชัน ให้พยายามตั้งชื่อที่ไม่ซ้ำกัน ซึ่งอาจเกี่ยวข้องกับ
ชื่อของส่วนเสริม หากส่วนเสริมที่ติดตั้งไว้ตั้งแต่ 2 รายการขึ้นไปกำหนดฟังก์ชันที่กำหนดเองซึ่งมีชื่อเดียวกัน ผู้ใช้จะใช้ได้เพียงฟังก์ชันเดียวเท่านั้น
- ส่วนเสริมควรสื่อสารอย่างชัดเจนว่ามีฟังก์ชันที่กำหนดเองใดบ้าง
โปรดระบุความคิดเห็น JSDoc ที่ถูกต้องสำหรับฟังก์ชันที่กำหนดเองเพื่อให้ Apps Script แสดงข้อมูลการเติมข้อความอัตโนมัติแก่ผู้ใช้ได้
นอกจากนี้ ให้พิจารณาจัดทำเอกสารเพิ่มเติมเกี่ยวกับฟังก์ชันที่กำหนดเองในส่วนเสริมเองหรือในหน้าเว็บสนับสนุนส่วนเสริม
- ฟังก์ชันที่กำหนดเองซึ่งทำงานไม่เสร็จภายใน 30 วินาทีจะล้มเหลวโดยมีข้อผิดพลาด
Internal error executing the custom function
สร้างประสบการณ์ที่ดีให้แก่ผู้ใช้โดยจำกัดปริมาณการประมวลผลที่คุณทำในฟังก์ชันที่กำหนดเอง
เพิ่มประสิทธิภาพฟังก์ชัน
เมื่อทำได้
- ฟังก์ชันที่กำหนดเองจะใช้บริการ Apps Script ที่ต้องมีการให้สิทธิ์ไม่ได้
และจะล้มเหลวพร้อมข้อผิดพลาด
You do not have permission to call X service
หากมีการพยายามใช้
ใช้เฉพาะ
บริการที่ได้รับอนุญาต
ในฟังก์ชันที่กำหนดเอง
- ฟังก์ชันที่กำหนดเองแต่ละฟังก์ชันในชีตจะทำให้เกิดการเรียกใช้เซิร์ฟเวอร์ Apps Script แยกกัน
หากผู้ใช้พยายามใช้ฟังก์ชันที่กำหนดเองในเซลล์มากเกินไป ฟังก์ชันอาจทำงานช้า เพื่อลดปัญหานี้ ให้ใช้ฟังก์ชันที่กำหนดเอง
ที่ง่ายที่สุด หากต้องการให้ฟังก์ชันทำการประมวลผลที่ซับซ้อนหรือขยาย
ออกไป อย่าใช้ฟังก์ชันที่กำหนดเอง แต่ให้ระบุฟังก์ชันดังกล่าวผ่าน
รายการเมนู กล่องโต้ตอบ หรือการโต้ตอบแถบด้านข้างแทน
มาโครชีต
มาโครช่วยให้คุณบันทึกการดำเนินการ
ที่ทำใน Google ชีตและทำซ้ำในภายหลังได้ด้วยแป้นพิมพ์ลัด เมื่อสร้างมาโครในชีต ระบบจะเพิ่มมาโครเป็นฟังก์ชันมาโครในโปรเจ็กต์ Apps Script ที่เชื่อมโยงกับชีตนั้น ดูข้อมูลเพิ่มเติมเกี่ยวกับมาโครได้ที่มาโครใน Google ชีต
ขออภัย คุณไม่สามารถเผยแพร่มาโครชีตพร้อมกับส่วนเสริมได้ หากคุณรวมคำจำกัดความของมาโครไว้ในไฟล์ Manifest ของส่วนเสริม ผู้ใช้ส่วนเสริมนั้นจะใช้มาโครไม่ได้
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-31 UTC
[null,null,["อัปเดตล่าสุด 2025-07-31 UTC"],[[["\u003cp\u003eGoogle Sheets add-ons enhance spreadsheets with custom workflows, external system connections, and integration with other Google Workspace apps.\u003c/p\u003e\n"],["\u003cp\u003eAdd-ons, built using Apps Script, enable data manipulation, custom menus, dialogs, and functions, triggered by specific events.\u003c/p\u003e\n"],["\u003cp\u003eCustom functions extend Google Sheets' built-in formulas, accessible directly within cells, but require adherence to naming and usage guidelines.\u003c/p\u003e\n"],["\u003cp\u003eGoogle Sheet add-ons provide extended functionality but cannot currently distribute or utilize pre-recorded macros.\u003c/p\u003e\n"]]],["Google Sheets add-ons, built with Apps Script, extend functionality by allowing users to read, edit, visualize, and format data. They can access the Google Sheets API, create custom menus, dialogs, sidebars, and custom functions. Add-ons can also use triggers to run functions on specific events. Custom functions, when created within an add-on, become immediately available to users after installation, following specific naming and usage guidelines. Macros, while recordable actions in Sheets, are not distributable with add-ons.\n"],null,["# Extending Google Sheets with add-ons\n\n[Google Sheets](https://workspace.google.com/products/sheets/) is a cloud-based\nspreadsheet solution with real-time collaboration and powerful tools to\nvisualize, process and communicate data.\n\nYou can extend Sheets with add-ons that build customized workflow improvements,\nestablish connectivity to third-party systems, and integrate your Sheets data\nwith other Google Workspace applications (like\nGoogle Slides).\n\nYou can see the Sheets add-ons others have built on the\n[Google Workspace Marketplace](https://workspace.google.com/marketplace/category/works-with-spreadsheet).\n\nWhat you can do\n---------------\n\nHere are a few things you can do with an add-on that extends Google Sheets:\n\n- You can read, edit, visualize, and format data in Google Sheets spreadsheets using the built-in Apps Script [Spreadsheet service](/apps-script/reference/spreadsheet). The service also lets you create and modify conditional formatting and data validation rules.\n- You can use the Apps Script [advanced Sheets service](/apps-script/advanced/sheets) to access the [Google Sheets API](/workspace/sheets/api) directly.\n- You can create [custom menus](/workspace/add-ons/concepts/menus) and define multiple [custom dialogs and sidebars](/workspace/add-ons/concepts/dialogs) interfaces using standard HTML and CSS.\n- You can include [custom function](#custom_functions) definitions in your add-on.\n- You can use add-ons [triggers](#triggers) that run specified functions when certain triggering events occur.\n\nSheets add-ons are built using Apps Script. To learn more about how to access\nand manage Google Sheets with Apps Script, see\n[Extending Google Sheets](/apps-script/guides/sheets).\n\nSheet structure\n---------------\n\nA Google Sheets spreadsheet consists of one or more sheets. Each sheet is\nessentially a 2D grid of cells into which text, numbers, links, or other\nvalues can be stored. A group of one or more adjacent cells is called a\n*range*.\n\nThe Apps Script [Spreadsheet service](/apps-script/reference/spreadsheet)\nprovides several classes to represent organizational structures in Sheets\n(such as [`Sheet`](/apps-script/reference/spreadsheet/sheet) and\n[`Range`](/apps-script/reference/spreadsheet/range)). You can use these\nclasses to read and modify Sheets data and behavior.\n\nTriggers\n--------\n\nApps Script [triggers](/workspace/add-ons/concepts/editor-triggers) let a script project\nexecute a specified function when certain conditions are met, such as when a\nspreadsheet is opened or when an add-on is installed.\n\nSee [add-on triggers](/workspace/add-ons/concepts/editor-triggers) for more information\non what triggers can be used with Sheets add-ons and what restrictions apply\nto their use.\n\nCustom functions\n----------------\n\nGoogle Sheets has a number of\n[built-in functions](https://support.google.com/docs/table/25273?ref_topic=1361471)\nlike `SUM` and `AVERAGE` that can be invoked from within a Google Sheet cell.\nSheets add-ons can define additional\n[custom functions](/apps-script/guides/sheets/functions) to supplement these\nbuilt-in functions. When a user\ninstalls the add-on, any defined custom functions included with the add-on\nbecome available immediately. It is possible for an add-on to consist of\nonly custom function definitions. Custom function definitions are primarily\nshared with others by publishing an add-on containing the definitions.\n\n### Creating add-on custom functions\n\nAny function defined in an add-on script project can be used as a custom\nfunction. Once the function is implemented and the add-on is installed, you\ncan call the custom function like any other built-in Sheets function: in a\nSheet cell, enter the `=` followed by the name of the function and any required\nparameters. If there are no errors, the result returned by the function is\nplaced in the Sheet cell, overflowing to neighboring cells as necessary.\n\nWhen creating custom functions in an add-on you should follow\nthe general custom function guidelines:\n\n- [Function naming guidelines](/apps-script/guides/sheets/functions#naming)\n- [Defining function arguments](/apps-script/guides/sheets/functions#arguments)\n- [Defining the function return value](/apps-script/guides/sheets/functions#return_values)\n- [Custom function data types](/apps-script/guides/sheets/functions#data_types)\n- [Enabling autocomplete using JSDoc](/apps-script/guides/sheets/functions#autocomplete)\n- [Services custom functions can use](/apps-script/guides/sheets/functions#using_apps_script_services)\n- [Optimizing custom functions](/apps-script/guides/sheets/functions#optimization)\n\nIn addition, custom functions defined in add-ons have some special\nconsiderations:\n\n- When naming your function, try to create a unique name, perhaps related to the name of your add-on. If two or more installed add-ons define custom functions with the same name, users can only use one of them.\n- Your add-on should clearly communicate what custom functions it provides. Be sure to provide accurate JSDoc comments for your custom functions so that Apps Script can present [autocomplete](/apps-script/guides/sheets/functions#autocomplete) information to the user. In addition, consider providing additional documentation of the custom functions either in the add-on itself or on an add-on support web page.\n- Custom functions that don't complete in under 30 seconds fail with an `Internal error executing the custom function` error. Build a good user experience by limiting the amount of processing you do in a custom function. [Optimize](/apps-script/guides/sheets/functions#optimization) the function where you can.\n- Custom functions can't use Apps Script services that require authorization, and fail with a `You do not have permission to call X service` error if this is attempted. Only use the [permitted services](/apps-script/guides/sheets/functions#using_apps_script_services) in your custom function.\n- Each custom function in a sheet results in a separate call to the Apps Script servers. If a user attempts to use custom functions in too many cells, the functions may execute slowly. To mitigate this, keep your custom functions as simple as possible. If you need the function to perform complex or extended processing, don't use a custom function---provide that functionality via a menu item, dialog, or sidebar interaction instead.\n\nSheets macros\n-------------\n\n[Macros](https://support.google.com/docs/answer/7665004) let you record actions\ntaken in Google Sheets and repeat them later with a keyboard shortcut. When a\nmacro is created in a sheet, it is added as a *macro function* in an Apps\nScript project [bound](/apps-script/guides/bound) to that sheet. For more\ninformation about macros, see\n[Google Sheets macros](/apps-script/guides/sheets/macros).\n\nUnfortunately, Sheets macros *can't* be distributed with add-ons. If you include\na macro definition in an add-on's manifest, it is unavailable to users of that\nadd-on."]]