程式設計層級:入門
時間長度:5 分鐘
專案類型:透過時間驅動觸發條件的自動化動作
目標
- 瞭解解決方案的功能。
- 瞭解 Apps Script 服務在 解決方案
- 設定指令碼。
- 執行指令碼。
認識這項解決方案
如果購買一個股票而價值下降,您可以銷售該股票、購買 以及申請預扣稅額。這種方式稱為減稅收。 在你的 Google 試算表中列出股票,若情況符合,你就會收到電子郵件快訊 低於購買價格的股價
運作方式
這個試算表會使用 Google 財經內建函式 ,取得股市目前的價格。腳本 會比較 每個所列股票的價格和目前價格。接著,該工具會以電子郵件將清單 低於購買價格的股票。您可以將指令碼設為 能以適合自己的頻率執行
Apps Script 服務
這項解決方案使用下列服務:
必要條件
如要使用這個範例,您必須具備下列先決條件:
- Google 帳戶 (Google Workspace 帳戶可能會 需要管理員核准)。
- 可存取網際網路的網路瀏覽器。
設定指令碼
- 點選下方按鈕即可建立「稅金收集快訊」的副本
範例試算表這項操作的 Apps Script 專案
解決方案附加在試算表上
建立副本 - 在複製的試算表中,使用你的股票資訊更新工作表。 或使用提供的測試資料
執行指令碼
- 在複製的試算表中按一下「擴充功能」 >>「Apps Script」。
- 在函式下拉式選單中,選取「checkLosses」checkLosses。
- 按一下「執行」。
出現提示時,請授權指令碼。 如果 OAuth 同意畫面顯示「這個應用程式未經驗證」警告, 如要繼續,請選取「進階」圖示 > 前往 {Project Name} (不安全)。
請在電子郵件中查看降價低於購買價格的股票清單。 如果您沒有收到電子郵件,請查看 定價低於購買價格
建立時間導向的觸發條件
- 返回指令碼專案。
- 按一下左側的「觸發條件」圖示 。
- 按一下右下方的「新增觸發條件」。
- 確認「Choose which function to run」(選擇要執行的函式) 部分已選取「checkLosses」。
- 在「選取事件來源」部分,選取「時間導向」。
- 設定所需的指令碼執行頻率,然後按一下「儲存」。
查看程式碼
如要查看這個解決方案的 Apps Script 程式碼,請按一下 查看原始碼如下:
查看原始碼
Code.gs
貢獻者
這個範例是由產品管理與平台的 Jeremy Glassenberg 所製作 策略顧問。在 Twitter 尋找 Jeremy @jglassenberg。
這個範例是由 Google 在 Google Developers 專家的協助下維護。