[GAS] UIクラスとBrowserクラス

gas
本項は書きたての記事です。正確な情報は公式サイト、公式ドキュメント、記載の参照サイトでご確認ください。

目次

+ 読む

UIクラスとBrowserクラス

どちらもスプレッドシート等でダイアログを出すクラスだが、前者はボタンやテキストボックスを配置できるのに対し、後者は文字出力だけである。
またBrowserクラスは「このクラスのメソッドは Google スプレッドシートのコンテキストでのみ使用できます。」と記載あるため
ほかのGoogleApps(Googleドキュメント、スライド等)では利用できない欠点がある。

ダイアログ表示には基本UIクラスを使い、統一感を出したほうが良いと考える。


コード1

- 読む
//UIインスタンス
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.');
}
 
 
 






公式参考

[ Class Ui  |  Apps Script  |  Google Developers ]
( https://developers.google.com/apps-script/reference/base/ui?hl=ja )
[ Class Browser  |  Apps Script  |  Google Developers ]
( https://developers.google.com/apps-script/reference/base/browser?hl=ja )

参考

GAS ui.alertを使う?browser.msgBoxを使う?|good-sun(a03)|note
( https://note.com/0375/n/nc00fd0a0d91d )
【Google Apps Script (GAS)】ダイアログメッセージを表示する6つの方法 | 便利な世の中を便利に生きる♪
( https://benri-life.com/programming%E2%88%92learning/google-apps/1243/ )

タグ:

gas
最終更新:2023年04月24日 15:26