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()에서 반환하는 미리 결정되고 현지화된 대화상자 버튼을 나타내는 열거형입니다.
ButtonSetButtonSet알림 또는 메시지에 추가할 수 있는 하나 이상의 대화상자 버튼에 관한 미리 결정되고 현지화된 세트를 나타내는 열거형입니다.

메서드

메서드반환 유형간략한 설명
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대화상자에 표시할 메시지입니다.

Return

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대화상자에 표시되도록 설정된 버튼입니다.

Return

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대화상자에 표시되도록 설정된 버튼입니다.

Return

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();
}

Return

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최상위 라벨은 모든 주요 단어를 대문자로 표기하고 하위 메뉴는 첫 번째 단어를 대문자로 표기하는 메뉴 라벨입니다.

Return

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대화상자에 표시할 메시지입니다.

Return

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대화상자에 표시되도록 설정된 버튼입니다.

Return

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대화상자에 표시되도록 설정된 버튼입니다.

Return

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

지원 중단된 메서드