Class Ui

UI

스크립트가 메뉴, 대화상자, 사이드바와 같은 기능을 추가할 수 있도록 하는 Google 앱의 사용자 인터페이스 환경 인스턴스입니다. 스크립트는 열려 있는 편집기의 현재 인스턴스, 그리고 스크립트가 편집기에 컨테이너에 결합된 경우에만 UI와 상호작용할 수 있습니다.

// Display a dialog box with a title, message, input field, and "Yes" and "No" buttons. The
// user can also close the dialog by clicking the close button in its title bar.
var ui = SpreadsheetApp.getUi();
var response = ui.prompt('Getting to know you', 'May I know your name?', ui.ButtonSet.YES_NO);

// Process the user's response.
if (response.getSelectedButton() == ui.Button.YES) {
  Logger.log('The user\'s name is %s.', response.getResponseText());
} else if (response.getSelectedButton() == ui.Button.NO) {
  Logger.log('The user didn\'t want to provide a name.');
} else {
  Logger.log('The user clicked the close button in the dialog\'s title bar.');
}

속성

속성유형설명
ButtonButton사용자가 클릭한 대화상자의 버튼을 나타내기 위해 알림 또는 PromptResponse.getSelectedButton()에서 반환된 미리 결정되고 현지화된 대화상자 버튼을 나타내는 enum입니다.
ButtonSetButtonSet알림 또는 프롬프트에 추가할 수 있는 하나 이상의 대화상자 버튼의 미리 결정되고 현지화된 집합을 나타내는 enum입니다.

방법

메서드반환 유형간략한 설명
alert(prompt)Button사용자의 편집기에서 지정된 메시지와 '확인' 버튼이 있는 대화상자를 엽니다.
alert(prompt, buttons)Button사용자의 편집기에서 지정된 메시지와 버튼 모음이 포함된 대화상자를 엽니다.
alert(title, prompt, buttons)Button사용자의 편집기에서 지정된 제목, 메시지, 버튼 모음이 포함된 대화상자를 엽니다.
createAddonMenu()Menu편집기의 확장 프로그램 메뉴에 하위 메뉴를 삽입하는 데 사용할 수 있는 빌더를 만듭니다.
createMenu(caption)Menu편집기의 사용자 인터페이스에 메뉴를 추가하는 데 사용할 수 있는 빌더를 만듭니다.
prompt(prompt)PromptResponse사용자의 편집기에서 주어진 메시지와 '확인' 버튼이 있는 입력 대화상자를 엽니다.
prompt(prompt, buttons)PromptResponse사용자의 편집기에서 지정된 메시지와 버튼 집합을 포함하는 입력 대화상자를 엽니다.
prompt(title, prompt, buttons)PromptResponse사용자의 편집기에서 지정된 제목, 메시지, 버튼 모음이 포함된 입력 대화상자를 엽니다.
showModalDialog(userInterface, title)void사용자 편집기에서 클라이언트 측 콘텐츠가 포함된 모달 대화상자를 엽니다.
showModelessDialog(userInterface, title)void사용자 편집기에서 클라이언트 측 콘텐츠가 포함된 모달리스 대화상자를 엽니다.
showSidebar(userInterface)void사용자 편집기에서 클라이언트 측 콘텐츠가 포함된 사이드바를 엽니다.

자세한 문서

alert(prompt)

사용자의 편집기에서 지정된 메시지와 '확인' 버튼이 있는 대화상자를 엽니다. 이 메서드는 대화상자가 열려 있는 동안 서버 측 스크립트를 정지합니다. 사용자가 대화상자를 닫은 후에 스크립트가 다시 시작되지만 Jdbc 연결과 LockService 잠금은 정지 기간 동안 유지되지 않습니다. 자세한 내용은 대화상자 및 사이드바 가이드를 참고하세요.

// Display "Hello, world" in a dialog box with an "OK" button. The user can also close the
// dialog by clicking the close button in its title bar.
SpreadsheetApp.getUi().alert('Hello, world');

매개변수

이름유형설명
promptString대화상자에 표시할 메시지입니다.

리턴

Button - 사용자가 클릭한 버튼입니다.


alert(prompt, buttons)

사용자의 편집기에서 지정된 메시지와 버튼 모음이 포함된 대화상자를 엽니다. 이 메서드는 대화상자가 열려 있는 동안 서버 측 스크립트를 정지합니다. 사용자가 대화상자를 닫은 후에 스크립트가 다시 시작되지만 Jdbc 연결과 LockService 잠금은 정지 기간 동안 유지되지 않습니다. 자세한 내용은 대화상자 및 사이드바 가이드를 참고하세요.

// Display a dialog box with a message and "Yes" and "No" buttons. The user can also close the
// dialog by clicking the close button in its title bar.
var ui = SpreadsheetApp.getUi();
var response = ui.alert('Are you sure you want to continue?', ui.ButtonSet.YES_NO);

// Process the user's response.
if (response == ui.Button.YES) {
  Logger.log('The user clicked "Yes."');
} else {
  Logger.log('The user clicked "No" or the close button in the dialog\'s title bar.');
}

매개변수

이름유형설명
promptString대화상자에 표시할 메시지입니다.
buttonsButtonSet대화상자에 표시되도록 설정된 버튼입니다.

리턴

Button - 사용자가 클릭한 버튼입니다.


alert(title, prompt, buttons)

사용자의 편집기에서 지정된 제목, 메시지, 버튼 모음이 포함된 대화상자를 엽니다. 이 메서드는 대화상자가 열려 있는 동안 서버 측 스크립트를 정지합니다. 사용자가 대화상자를 닫은 후에 스크립트가 다시 시작되지만 Jdbc 연결과 LockService 잠금은 정지 기간 동안 유지되지 않습니다. 자세한 내용은 대화상자 및 사이드바 가이드를 참고하세요.

// Display a dialog box with a title, message, and "Yes" and "No" buttons. The user can also
// close the dialog by clicking the close button in its title bar.
var ui = SpreadsheetApp.getUi();
var response = ui.alert('Confirm', 'Are you sure you want to continue?', ui.ButtonSet.YES_NO);

// Process the user's response.
if (response == ui.Button.YES) {
  Logger.log('The user clicked "Yes."');
} else {
  Logger.log('The user clicked "No" or the close button in the dialog\'s title bar.');
}

매개변수

이름유형설명
titleString대화상자 위에 표시할 제목입니다.
promptString대화상자에 표시할 메시지입니다.
buttonsButtonSet대화상자에 표시되도록 설정된 버튼입니다.

리턴

Button - 사용자가 클릭한 버튼입니다.


createAddonMenu()

편집기의 확장 프로그램 메뉴에 하위 메뉴를 삽입하는 데 사용할 수 있는 빌더를 만듭니다. 메뉴는 Menu.addToUi()가 호출될 때까지 실제로 업데이트되지 않습니다. 스크립트가 부가기능으로 실행 중인 경우 하위 메뉴 이름은 웹 스토어의 부가기능 이름과 일치합니다. 스크립트가 문서에 직접 결합되면 하위 메뉴 이름이 스크립트의 이름과 일치합니다. 자세한 내용은 메뉴 가이드를 참고하세요.

// Add an item to the Add-on menu, under a sub-menu whose name is set automatically.
function onOpen(e) {
  SpreadsheetApp.getUi()
      .createAddonMenu()
      .addItem('Show', 'showSidebar')
      .addToUi();
}

리턴

Menu - 새 메뉴 빌더입니다.


createMenu(caption)

편집기의 사용자 인터페이스에 메뉴를 추가하는 데 사용할 수 있는 빌더를 만듭니다. Menu.addToUi()가 호출될 때까지 메뉴가 실제로 추가되지 않습니다. 자세한 내용은 메뉴 가이드를 참고하세요. 최상위 메뉴 라벨은 모두 제목 대문자 (모든 주요 단어를 대문자로 표시)를 사용해야 하지만, 하위 메뉴 라벨은 문장 첫 글자만 대문자로 표기해야 합니다 (첫 번째 단어만 대문자로 표기해야 함). 스크립트가 부가기능으로 게시되면 caption 매개변수가 무시되고 메뉴가 확장 프로그램 메뉴의 하위 메뉴(createAddonMenu()와 같음)로 추가됩니다.

// Add a custom menu to the active document, including a separator and a sub-menu.
function onOpen(e) {
  SpreadsheetApp.getUi()
      .createMenu('My Menu')
      .addItem('My menu item', 'myFunction')
      .addSeparator()
      .addSubMenu(SpreadsheetApp.getUi().createMenu('My sub-menu')
          .addItem('One sub-menu item', 'mySecondFunction')
          .addItem('Another sub-menu item', 'myThirdFunction'))
      .addToUi();
}

매개변수

이름유형설명
captionString최상위 메뉴에서는 모든 주요 단어를 대문자로 표기하거나 하위 메뉴의 경우 첫 번째 단어만 대문자로 표기한 메뉴 라벨입니다.

리턴

Menu - 새 메뉴 빌더입니다.


prompt(prompt)

사용자의 편집기에서 주어진 메시지와 '확인' 버튼이 있는 입력 대화상자를 엽니다. 이 메서드는 대화상자가 열려 있는 동안 서버 측 스크립트를 정지합니다. 사용자가 대화상자를 닫은 후에 스크립트가 다시 시작되지만 Jdbc 연결과 LockService 잠금은 정지 기간 동안 유지되지 않습니다. 자세한 내용은 대화상자 및 사이드바 가이드를 참고하세요.

// Display a dialog box with a message, input field, and an "OK" button. The user can also
// close the dialog by clicking the close button in its title bar.
var ui = SpreadsheetApp.getUi();
var response = ui.prompt('Enter your name:');

// Process the user's response.
if (response.getSelectedButton() == ui.Button.OK) {
  Logger.log('The user\'s name is %s.', response.getResponseText());
} else {
  Logger.log('The user clicked the close button in the dialog\'s title bar.');
}

매개변수

이름유형설명
promptString대화상자에 표시할 메시지입니다.

리턴

PromptResponse - 사용자의 응답을 나타냅니다.


prompt(prompt, buttons)

사용자의 편집기에서 지정된 메시지와 버튼 집합을 포함하는 입력 대화상자를 엽니다. 이 메서드는 대화상자가 열려 있는 동안 서버 측 스크립트를 정지합니다. 사용자가 대화상자를 닫은 후에 스크립트가 다시 시작되지만 Jdbc 연결과 LockService 잠금은 정지 기간 동안 유지되지 않습니다. 자세한 내용은 대화상자 및 사이드바 가이드를 참고하세요.

// Display a dialog box with a message, input field, and "Yes" and "No" buttons. The user can
// also close the dialog by clicking the close button in its title bar.
var ui = SpreadsheetApp.getUi();
var response = ui.prompt('May I know your name?', ui.ButtonSet.YES_NO);

// Process the user's response.
if (response.getSelectedButton() == ui.Button.YES) {
  Logger.log('The user\'s name is %s.', response.getResponseText());
} else if (response.getSelectedButton() == ui.Button.NO) {
  Logger.log('The user didn\'t want to provide a name.');
} else {
  Logger.log('The user clicked the close button in the dialog\'s title bar.');
}

매개변수

이름유형설명
promptString대화상자에 표시할 메시지입니다.
buttonsButtonSet대화상자에 표시되도록 설정된 버튼입니다.

리턴

PromptResponse - 사용자의 응답을 나타냅니다.


prompt(title, prompt, buttons)

사용자의 편집기에서 지정된 제목, 메시지, 버튼 모음이 포함된 입력 대화상자를 엽니다. 이 메서드는 대화상자가 열려 있는 동안 서버 측 스크립트를 정지합니다. 스크립트는 사용자가 대화상자를 닫은 후에 다시 시작되지만 Jdbc 연결과 LockService 잠금은 정지 기간 동안 유지되지 않습니다. 자세한 내용은 대화상자 및 사이드바 가이드를 참고하세요.

// Display a dialog box with a title, message, input field, and "Yes" and "No" buttons. The
// user can also close the dialog by clicking the close button in its title bar.
var ui = SpreadsheetApp.getUi();
var response = ui.prompt('Getting to know you', 'May I know your name?', ui.ButtonSet.YES_NO);

// Process the user's response.
if (response.getSelectedButton() == ui.Button.YES) {
  Logger.log('The user\'s name is %s.', response.getResponseText());
} else if (response.getSelectedButton() == ui.Button.NO) {
  Logger.log('The user didn\'t want to provide a name.');
} else {
  Logger.log('The user clicked the close button in the dialog\'s title bar.');
}

매개변수

이름유형설명
titleString대화상자 위에 표시할 제목입니다.
promptString대화상자에 표시할 메시지입니다.
buttonsButtonSet대화상자에 표시되도록 설정된 버튼입니다.

리턴

PromptResponse - 사용자의 응답을 나타냅니다.


showModalDialog(userInterface, title)

사용자 편집기에서 클라이언트 측 콘텐츠가 포함된 모달 대화상자를 엽니다. 이 메서드는 대화상자가 열려 있는 동안 서버 측 스크립트를 정지하지 않습니다. 서버 측 스크립트와 통신하려면 클라이언트 측 구성요소가 HtmlServicegoogle.script API를 사용하여 비동기 콜백을 실행해야 합니다. 프로그래매틱 방식으로 대화상자를 닫으려면 HtmlService 웹 앱의 클라이언트 측에서 google.script.host.close()를 호출합니다. 자세한 내용은 대화상자 및 사이드바 가이드를 참고하세요.

모달 대화상자는 사용자가 대화상자 이외의 다른 항목과 상호작용하는 것을 방지합니다. 반면에 모드리스 대화상자사이드바를 사용하면 사용자가 편집기와 상호작용할 수 있습니다. 거의 모든 경우 모달 대화상자나 사이드바가 모달리스 대화상자보다 더 나은 선택입니다.

// Display a modal dialog box with custom HtmlService content.
var htmlOutput = HtmlService
    .createHtmlOutput('<p>A change of speed, a change of style...</p>')
    .setWidth(250)
    .setHeight(300);
SpreadsheetApp.getUi().showModalDialog(htmlOutput, 'My add-on');

매개변수

이름유형설명
userInterfaceObject표시할 인터페이스를 나타내는 HtmlOutput입니다.
titleString대화상자의 제목입니다. userInterface 객체에서 setTitle()을 호출하여 설정된 제목을 재정의합니다.

승인

이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.

  • https://www.googleapis.com/auth/script.container.ui

showModelessDialog(userInterface, title)

사용자 편집기에서 클라이언트 측 콘텐츠가 포함된 모달리스 대화상자를 엽니다. 이 메서드는 대화상자가 열려 있는 동안 서버 측 스크립트를 정지하지 않습니다. 서버 측 스크립트와 통신하려면 클라이언트 측 구성요소가 HtmlServicegoogle.script API를 사용하여 비동기 콜백을 실행해야 합니다. 프로그래매틱 방식으로 대화상자를 닫으려면 HtmlService 웹 앱의 클라이언트 측에서 google.script.host.close()를 호출합니다. 자세한 내용은 대화상자 및 사이드바 가이드를 참고하세요.

모달리스 대화상자를 사용하면 사용자가 대화상자 뒤의 편집기와 상호작용할 수 있습니다. 반면에 모달 대화상자는 그렇지 않습니다. 대부분의 경우 모달 대화상자 또는 사이드바가 모달리스 대화상자보다 더 나은 선택입니다.

// Display a modeless dialog box with custom HtmlService content.
var htmlOutput = HtmlService
    .createHtmlOutput('<p>A change of speed, a change of style...</p>')
    .setWidth(250)
    .setHeight(300);
SpreadsheetApp.getUi().showModelessDialog(htmlOutput, 'My add-on');

매개변수

이름유형설명
userInterfaceObject표시할 인터페이스를 나타내는 HtmlOutput입니다.
titleString대화상자의 제목입니다. userInterface 객체에서 setTitle()을 호출하여 설정된 제목을 재정의합니다.

승인

이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.

  • https://www.googleapis.com/auth/script.container.ui

showSidebar(userInterface)

사용자 편집기에서 클라이언트 측 콘텐츠가 포함된 사이드바를 엽니다. 이 메서드는 사이드바가 열려 있는 동안 서버 측 스크립트를 정지하지 않습니다. 서버 측 스크립트와 통신하려면 클라이언트 측 구성요소가 HtmlServicegoogle.script API를 사용하여 비동기 콜백을 실행해야 합니다. 프로그래매틱 방식으로 사이드바를 닫으려면 HtmlService 웹 앱의 클라이언트 측에서 google.script.host.close()를 호출합니다. 자세한 내용은 대화상자 및 사이드바 가이드를 참고하세요.

사이드바는 왼쪽에서 오른쪽으로 쓰는 언어를 사용하는 환경의 사용자에는 편집기의 오른쪽에, 오른쪽에서 왼쪽으로 쓰는 언어를 사용하는 경우에는 편집기의 왼쪽에 표시됩니다. 스크립트에서 표시하는 모든 사이드바의 너비는 300픽셀입니다.

// Display a sidebar with custom HtmlService content.
var htmlOutput = HtmlService
    .createHtmlOutput('<p>A change of speed, a change of style...</p>')
    .setTitle('My add-on');
SpreadsheetApp.getUi().showSidebar(htmlOutput);

매개변수

이름유형설명
userInterfaceObject표시할 인터페이스를 나타내는 HtmlOutput입니다.

승인

이 방법을 사용하는 스크립트는 다음 범위 중 하나 이상을 승인해야 합니다.

  • https://www.googleapis.com/auth/script.container.ui

지원 중단된 메서드