2022年1月6日 星期四

【Google教學】如何在Google文件中加入自訂選單並可以執行程式

 之前在試算表中可以拉圖形設定要執行的程式,但是在文件中就不能這樣用,所以我們改成透過選單的方式來控制要執行的程式。



工具/指令碼編輯器

function onOpen() {

  

  var doc_ui = DocumentApp.getUi();

  

      doc_ui.createMenu('彰化一整天教學')

      .addItem('輸入測試', 'input_test')

      .addSeparator()

      .addItem('說您好', 'say_hello')

      .addToUi();


}


function say_hello()

{

  var ui = DocumentApp.getUi();

  ui.alert('bestdaylong','您好!!',ui.ButtonSet.OK);

}


function input_test()

{

  //https://developers.google.com/apps-script/reference/base/ui#alert(String)

  var doc_ui = DocumentApp.getUi();

  var your_name = doc_ui.prompt('bestdaylong', '請輸入您的名字', doc_ui.ButtonSet.YES_NO);

  DocumentApp.getUi().alert(your_name.getResponseText()+",您好!");

}




沒有留言:

張貼留言

如何利用 Google 試算表與 Apps Script 自訂多元線上訂購單與訂單查詢系統

在網路銷售(例如使用 LINE 群組或社群平台賣東西)的過程中,店家經常需要因應不同的節慶或行銷活動,調整訂購單的內容與優惠方案。例如:平時的活動是「買 10 包送 2 包」;每月 15 號則是「原味買百包送 40 包」;到了母親節或中秋節,又會推出不同的促銷組合。 為了讓商家能...