تنظيم صفحاتك في مجموعات يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
يكون النص البرمجي مرتبطًا بملف في "جداول بيانات Google" أو "مستندات Google" أو "العروض التقديمية من Google" أو "نماذج Google" إذا تم إنشاؤه من ذلك المستند بدلاً من إنشائه كنص برمجي مستقل. يُطلق على الملف الذي يتم إرفاق نص برمجي مرتبط به اسم "حاوية". تتصرّف البرامج النصية المرتبطة بشكل عام مثل البرامج النصية المستقلة، باستثناء أنّها لا تظهر في Google Drive، ولا يمكن فصلها عن الملف المرتبطة به، كما أنّها تحصل على بعض الامتيازات الخاصة على الملف الرئيسي.
يُرجى العِلم أنّه يمكن أيضًا ربط النصوص البرمجية بـ "مواقع Google"، ولكن يتم نشر هذه النصوص البرمجية دائمًا تقريبًا على أنّها تطبيقات ويب. يمكن أيضًا أن تصبح البرامج النصية المرتبطة بـ "جداول بيانات Google" أو "مستندات Google" أو "العروض التقديمية من Google" أو "نماذج Google" تطبيقات ويب، على الرغم من أنّ هذا الإجراء غير شائع.
إنشاء نص برمجي مرتبط
"مستندات Google" أو "جداول بيانات Google" أو "العروض التقديمية من Google"
لإنشاء نص برمجي مرتبط في "مستندات Google" أو "جداول بيانات Google" أو "العروض التقديمية من Google"، افتح مستندًا في "مستندات Google" أو جدول بيانات في "جداول بيانات Google" أو عرضًا تقديميًا في "العروض التقديمية من Google"، ثم انقر على الإضافات>Apps Script. لإعادة فتح النص البرمجي في المستقبل، اتّبِع الخطوات نفسها أو افتح النص البرمجي من لوحة بيانات Apps Script.
نماذج Google
لإنشاء نص برمجي مرتبط في "نماذج Google"، افتح نموذجًا وانقر على "المزيد" more_vert>محرّر النصوص البرمجية. لإعادة فتح النص البرمجي في المستقبل، اتّبِع الخطوات نفسها أو افتح النص البرمجي من لوحة بيانات Apps Script.
طُرق خاصة
يمكن للنصوص البرمجية المرتبطة استدعاء بعض الطرق التي لا يمكن للنصوص البرمجية المستقلة استدعاؤها:
يمكن للبرامج النصية المرتبطة تخصيص "جداول بيانات Google" و"مستندات Google" و"نماذج Google" من خلال إضافة قوائم مخصّصة و مربّعات حوار أو أشرطة جانبية. يُرجى العِلم، مع ذلك، بأنّ النص البرمجي لا يمكنه التفاعل مع واجهة المستخدم إلا في النسخة الحالية من ملف مفتوح. أي أنّ النص البرمجي المرتبط بمستند واحد لا يمكنه التأثير في واجهة المستخدم لمستند آخر.
العوامل التي تؤدي إلى الظهور
يمكن للنصوص البرمجية المرتبطة استخدام المشغّلات البسيطة مثل الدالة الخاصة onOpen()، التي يتم تشغيلها تلقائيًا كلما فتح مستخدم لديه إذن تعديل ملفًا. وكما هو الحال مع جميع أنواع النصوص البرمجية، يمكنها أيضًا استخدام المشغّلات القابلة للتثبيت.
الدوال المخصّصة
الدالة المخصّصة هي دالة في نص برمجي مرتبط بـ "جداول بيانات Google" يمكنك طلبها مباشرةً من خلية باستخدام الصيغة =myFunctionName(). وبالتالي، تشبه الدوال المخصّصة المئات من الدوال المضمّنة في "جداول بيانات Google"، مثل AVERAGE أو SUM، إلا أنّك تحدّد سلوك الدالة المخصّصة.
الوصول إلى البرامج النصية المرتبطة
لا يمكن لأحد تنفيذ النص البرمجي المرتبط بحاوية سوى المستخدمين الذين لديهم إذن بتعديل الحاوية. لا يمكن للمتعاونين الذين لديهم إذن بالاطّلاع فقط فتح محرّر النصوص البرمجية، ولكن إذا أنشأوا نسخة من ملف الحاوية، سيصبحون مالكي النسخة ويمكنهم الاطّلاع على نسخة من النص البرمجي وتشغيلها.
تاريخ التعديل الأخير: 2025-08-04 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","easyToUnderstand","thumb-up"],["ساعَدني المحتوى في حلّ مشكلتي.","solvedMyProblem","thumb-up"],["غير ذلك","otherUp","thumb-up"]],[["لا يحتوي على المعلومات التي أحتاج إليها.","missingTheInformationINeed","thumb-down"],["الخطوات معقدة للغاية / كثيرة جدًا.","tooComplicatedTooManySteps","thumb-down"],["المحتوى قديم.","outOfDate","thumb-down"],["ثمة مشكلة في الترجمة.","translationIssue","thumb-down"],["مشكلة في العيّنات / التعليمات البرمجية","samplesCodeIssue","thumb-down"],["غير ذلك","otherDown","thumb-down"]],["تاريخ التعديل الأخير: 2025-08-04 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\u003cp\u003eBound scripts are Google Apps Scripts attached to Google Docs, Sheets, Slides, or Forms, offering special privileges to interact with their parent file.\u003c/p\u003e\n"],["\u003cp\u003eUnlike standalone scripts, bound scripts reside within their container file and cannot be detached, functioning like unpublished add-ons specific to that file.\u003c/p\u003e\n"],["\u003cp\u003eThey allow the use of special methods to programmatically access and manipulate the parent file's content and user interface.\u003c/p\u003e\n"],["\u003cp\u003eBound scripts can be shared by sharing the container file, enabling collaborators with edit access to run the script.\u003c/p\u003e\n"],["\u003cp\u003eThese scripts can also be published as add-ons, making them accessible to a wider audience through the add-on store.\u003c/p\u003e\n"]]],[],null,["A script is bound to a Google Sheets, Docs, Slides, or Forms file if it was\ncreated from that document rather than as a [standalone script](/apps-script/guides/standalone).\nThe file that a bound script is attached to is called a \"container.\"\nBound scripts generally behave like standalone scripts except that they\ndo not appear in Google Drive, they cannot be detached from the file\nthey are bound to, and they gain a few special privileges over the parent file.\n\nNote that scripts can also be bound to Google Sites, but these scripts are\nalmost always deployed as [web apps](/apps-script/guides/web). Scripts\nbound to Google Sheets, Docs, Slides, or Forms can also become web apps, although\nthis is uncommon.\n| **Note:** Bound scripts are effectively unpublished [add-ons](/workspace/add-ons/concepts/types#editor_add-ons) that function only for the file they are bound to.\n\nCreate a bound script\n\nGoogle Docs, Sheets, or Slides\n\nTo create a bound script in Google Docs, Sheets, or Slides, open a document in\nDocs, a spreadsheet in Sheets, or a presentation in Slides and click\n**Extensions**\n\\\u003e **Apps Script** . To reopen the script in\nthe future, do the same thing or open the script from the\n[Apps Script dashboard](https://script.google.com/home).\n\nGoogle Forms\n\nTo create a bound script in Google Forms, open a form\nand click More more_vert\n\\\u003e **Script\neditor** . To reopen the script in the\nfuture, do the same thing or open the script from the\n[Apps Script dashboard](https://script.google.com/home).\n| **Note:** The [`clasp`](/apps-script/guides/clasp) tool can't create bound scripts, but it can clone and edit them.\n\nSpecial methods\n\nBound scripts can call a few methods that standalone scripts cannot:\n\n- [`getActiveSpreadsheet()`](/apps-script/reference/spreadsheet/spreadsheet-app#getActiveSpreadsheet()), [`getActiveDocument()`](/apps-script/reference/document/document-app#getActiveDocument()), [`getActivePresentation()`](/apps-script/reference/slides/slides-app#getactivepresentation), and [`getActiveForm()`](/apps-script/reference/forms/form-app#getActiveForm()) allow bound scripts to refer to their parent file without referring to the file's ID.\n- [`getUi`](/apps-script/reference/spreadsheet/spreadsheet-app#getUi()) lets bound scripts access the user interface for their parent file to add [custom menus, dialogs, and sidebars](#custom_menus_dialogs_and_sidebars).\n- In Google Sheets, [`getActiveSheet()`](/apps-script/reference/spreadsheet/spreadsheet-app#getActiveSheet()), [`getActiveRange()`](/apps-script/reference/spreadsheet/spreadsheet-app#getActiveRange()), and [`getActiveCell()`](/apps-script/reference/spreadsheet/sheet#getActiveCell()) let the script determine the user's current sheet, selected range of cells, or selected individual cell. [`setActiveSheet(sheet)`](/apps-script/reference/spreadsheet/spreadsheet-app#setActiveSheet(Sheet)) and [`setActiveRange(range)`](/apps-script/reference/spreadsheet/spreadsheet-app#setActiveRange(Range)) let the script change those selections.\n- In Google Docs, [`getActiveTab()`](/apps-script/reference/document/document#getActiveTab()), [`getCursor()`](/apps-script/reference/document/document#getCursor()), and [`getSelection()`](/apps-script/reference/document/document#getSelection()) let the script determine the user's current tab, position of the user's cursor, or selected text. [`setActiveTab(tabId)`](/apps-script/reference/document/document#setActiveTab(String)), [`setCursor(position)`](/apps-script/reference/document/document#setCursor(Position)) and [`setSelection(range)`](/apps-script/reference/document/document#setSelection(Range)) let the script change those selections.\n\nFor more information, see the\n[guide to extending Google Sheets](/apps-script/guides/sheets) or\nthe [guide to extending Google Docs](/apps-script/guides/docs).\n| **Note:** These methods are only available to bound scripts run from the script editor, menu items, dialogs, sidebars, or triggers. When a bound script is run as a web app or via the [Apps Script API](/apps-script/api/how-tos/execute), these methods are not available.\n\nCustom menus, dialogs, and sidebars\n\nBound scripts can customize Google Sheets, Docs, and Forms by adding\n[custom menus](/apps-script/guides/menus) and\n[dialog boxes or sidebars](/apps-script/guides/dialogs). Keep in mind,\nhowever, that a script can only interact with the user interface for the\ncurrent instance of an open file. That is, a script bound to one document\ncannot affect the user interface of another document.\n| Add-ons can also add custom menus, dialogs and sidebars. It is recommended to develop add-ons using [standalone scripts](/apps-script/guides/standalone).\n\nTriggers\n\nBound scripts can use [simple triggers](/apps-script/guides/triggers)\nlike the special `onOpen()` function, which runs automatically whenever a file\nis opened by a user who has edit access. Like all types of scripts, they can\nalso use [installable triggers](/apps-script/guides/triggers/installable).\n\nCustom functions\n\nA [custom function](/apps-script/guides/sheets/functions) is a function in a\nscript bound to Google Sheets that you call directly from a cell using the\nsyntax `=myFunctionName()`. Custom functions are thus similar to the hundreds of\n[built-in functions](https://support.google.com/drive/topic/1361471) in Sheets\nlike [`AVERAGE`](https://support.google.com/drive/answer/3093615) or\n[`SUM`](https://support.google.com/drive/answer/3093669) except that you define\nthe custom function's behavior.\n\nAccess to bound scripts\n\nOnly users who have permission to edit a container can run its bound script.\nCollaborators who have only view access can't open the script\neditor, although if they make a copy of the container file, they become the\nowner of the copy and can see and run a copy of the script.\n\nTo learn how to share a script's container file, refer to [Share files from\nGoogle Drive](https://support.google.com/drive/answer/2494822).\n| All container-bound scripts use the same owner, viewer, and editor access list defined for the container file. The container owner takes ownership of a new script project regardless of who created it."]]