스크립트는 클릭 시 Apps Script 함수를 실행하는 사용자 인터페이스 요소를 추가하여 특정 Google 제품을 확장할 수 있습니다. 가장 일반적인 예는 Google Docs, Sheets, Slides 또는 Forms의 맞춤 메뉴 항목에서 스크립트를 실행하는 것입니다. 하지만 Google Sheets에서 이미지와 그림을 클릭하여 스크립트 함수를 트리거할 수도 있습니다.
Google 문서, 스프레드시트, 프레젠테이션 또는 설문지의 맞춤 메뉴
Apps Script는 Google Docs, Sheets, Slides 또는 Forms에 새 메뉴를 추가할 수 있으며 각 메뉴 항목은 스크립트의 함수에 연결됩니다. (Google Forms에서는 맞춤 메뉴가 양식을 수정하기 위해 여는 편집자에게만 표시되며, 응답하기 위해 양식을 여는 사용자에게는 표시되지 않습니다.)
스크립트는 문서, 스프레드시트 또는 양식에 바인드된 경우에만 메뉴를 만들 수 있습니다. 사용자가 파일을 열 때 메뉴를 표시하려면 onOpen() 함수 내에 메뉴 코드를 작성합니다.
아래 예는 항목 하나가 있는 메뉴를 추가한 다음 시각적 구분선을 추가하고 다른 항목이 포함된 하위 메뉴를 추가하는 방법을 보여줍니다. (Google Sheets에서는 새 버전을 사용하지 않는 한 addMenu() 구문을 대신 사용해야 하며 하위 메뉴는 불가능합니다.) 사용자가 메뉴 항목 중 하나를 선택하면 해당 함수가 알림 대화상자를 엽니다. 열 수 있는 대화상자 유형에 대한 자세한 내용은 대화상자 및 사이드바 가이드를 참고하세요.
functiononOpen(){varui=SpreadsheetApp.getUi();//OrDocumentApp,SlidesApporFormApp.ui.createMenu('Custom Menu').addItem('First item','menuItem1').addSeparator().addSubMenu(ui.createMenu('Sub-menu').addItem('Second item','menuItem2')).addToUi();}functionmenuItem1(){SpreadsheetApp.getUi()//OrDocumentApp,SlidesApporFormApp..alert('You clicked the first menu item!');}functionmenuItem2(){SpreadsheetApp.getUi()//OrDocumentApp,SlidesApporFormApp..alert('You clicked the second menu item!');}
문서, 스프레드시트, 프레젠테이션 또는 양식에는 지정된 이름의 메뉴가 하나만 포함될 수 있습니다. 동일한 스크립트 또는 다른 스크립트에서 이름이 동일한 메뉴를 추가하면 새 메뉴가 이전 메뉴를 대체합니다. 파일이 열려 있는 동안에는 메뉴를 삭제할 수 없지만, 특정 속성이 설정된 경우 향후 메뉴를 건너뛰도록 onOpen() 함수를 작성할 수 있습니다.
Google Sheets의 클릭 가능한 이미지 및 그림
스크립트가 스프레드시트에 바인드되어 있는 경우 Google Sheets의 이미지나 그림에 Apps Script 함수를 할당할 수도 있습니다. 아래 예에서는 이를 설정하는 방법을 보여줍니다.
Google Sheets에서 메뉴 항목 확장 프로그램>Apps Script를 선택하여 스프레드시트에 바인딩된 스크립트를 만듭니다.
스크립트 편집기에서 코드를 삭제하고 아래 코드를 붙여넣습니다.
function showMessageBox() { Browser.msgBox('You clicked it!'); }
Sheets로 돌아가 삽입 > 이미지 또는 삽입 > 그림을 선택하여 이미지나 그림을 삽입합니다.
이미지나 그림을 삽입한 후 클릭합니다. 오른쪽 상단에 작은 드롭다운 메뉴 선택기가 표시됩니다. 이 버튼을 클릭하고 스크립트 할당을 선택합니다.
표시되는 대화상자에 실행하려는 Apps Script 함수의 이름을 괄호 없이 입력합니다(이 경우 showMessageBox). 확인을 클릭합니다.
[[["이해하기 쉬움","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(UTC)"],[[["\u003cp\u003eApps Script allows you to extend Google products like Docs, Sheets, Slides, and Forms by adding custom menus and clickable elements that trigger script functions.\u003c/p\u003e\n"],["\u003cp\u003eCustom menus can be created within these Google products, with each menu item linked to a specific function in your script, enhancing user interaction and functionality.\u003c/p\u003e\n"],["\u003cp\u003eIn Google Sheets, you can assign Apps Script functions to images and drawings, making them interactive elements that execute code when clicked in a web browser.\u003c/p\u003e\n"]]],[],null,["Scripts can extend certain Google products by adding user-interface elements\nthat, when clicked, execute an Apps Script function. The most common example is\nrunning a script from a custom menu item in Google Docs, Sheets, Slides,\nor Forms, but script functions can also be triggered by clicking on images and\ndrawings in Google Sheets.\n\nCustom menus in Google Docs, Sheets, Slides, or Forms\n\nApps Script can add new menus in Google Docs, Sheets, Slides,\nor Forms, with\neach menu item tied to a function in a script. (In Google Forms, custom menus\nare visible only to an editor who opens the form to modify it, not to a user who\nopens the form to respond.)\n\nA script can only create a menu if it is\n[bound](/apps-script/scripts_containers) to the document, spreadsheet, or form.\nTo display the menu when the user opens a file, write the menu code within an\n[`onOpen()`](/apps-script/understanding_triggers) function.\n\nThe example below shows how to add a [menu](/apps-script/reference/base/menu)\nwith one item, followed by a\n[visual separator](/apps-script/reference/base/menu#addSeparator()), then a\n[sub-menu](/apps-script/reference/base/menu#addSubMenu(Menu)) that contains\nanother item. (Note that in Google Sheets, unless you're using the\n[new version](https://support.google.com/drive/answer/3541068), you must use the\n[`addMenu()`](/apps-script/reference/spreadsheet/spreadsheet#addMenu(String,Object))\nsyntax instead, and sub-menus are not possible.) When the user selects either\nmenu item, a corresponding function opens an\n[alert](/apps-script/reference/base/ui#alert(String)) dialog. For more\ninformation on the types of dialogs you can open, see the\n[guide to dialogs and sidebars](/apps-script/guides/dialogs). \n\n function onOpen() {\n var ui = SpreadsheetApp.getUi();\n // Or DocumentApp, SlidesApp or FormApp.\n ui.createMenu('Custom Menu')\n .addItem('First item', 'menuItem1')\n .addSeparator()\n .addSubMenu(ui.createMenu('Sub-menu')\n .addItem('Second item', 'menuItem2'))\n .addToUi();\n }\n\n function menuItem1() {\n SpreadsheetApp.getUi() // Or DocumentApp, SlidesApp or FormApp.\n .alert('You clicked the first menu item!');\n }\n\n function menuItem2() {\n SpreadsheetApp.getUi() // Or DocumentApp, SlidesApp or FormApp.\n .alert('You clicked the second menu item!');\n }\n\nA document, spreadsheet, presentation, or form can only contain one menu with\na given name. If the same script or another script adds a menu with the same\nname, the new menu replaces the old. Menus cannot be removed while the file\nis open, although you can write your `onOpen()` function to skip the menu in\nthe future if a certain [property](/apps-script/guides/properties) is set.\n| **Note:** [Editor add-ons](/workspace/add-ons/concepts/types#editor_add-ons) can have menu items as well, but use [special rules](/workspace/add-ons/concepts/menus) they are defined.\n\nClickable images and drawings in Google Sheets\n\nYou can also assign an Apps Script function to an image or drawing in Google Sheets,\nso long as the script is [bound](/apps-script/scripts_containers) to the\nspreadsheet. The example below shows how to set this up.\n\n1. In Google Sheets, select the menu item **Extensions** \\\u003e **Apps Script** to create a script that is bound to the spreadsheet.\n2. Delete any code in the script editor and paste in the code below.\n\n function showMessageBox() {\n Browser.msgBox('You clicked it!');\n }\n\n3. Return to Sheets and insert an image or drawing by selecting\n **Insert \\\u003e Image** or **Insert \\\u003e Drawing**.\n\n4. After inserting the image or drawing, click it. A small drop-down menu\n selector appears in the top right-hand corner. Click it and choose\n **Assign script**.\n\n5. In the dialog box that appears, type the name of the Apps Script function\n that you want to run, without parentheses --- in this case, `showMessageBox`.\n Click **OK**.\n\n6. Click the image or drawing again. The function now executes.\n\n| **Note:** The script execution is only triggered by clicking the image or drawing in a web browser. The script doesn't execute if the image or drawing is clicked on mobile."]]