[GAS] UIクラスとBrowserクラス
本項は書きたての記事です。正確な情報は公式サイト、公式ドキュメント、記載の参照サイトでご確認ください。
目次
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.');
}
|
公式参考
参考
最終更新:2023年04月24日 15:26