
使用 App Inventor 讀取 Google 試算表 (多分頁篇)
之前有讀者問過我,如果要讀取的試算表有兩個以上的話,那是不是就要建立好幾個試算表?
其實只要建立一個試算表就夠了!
一個試算表底下可以建立多個工作表,所以今天就來介紹,如何讀取不同工作表的資料到 App Inventor 顯示。
這篇是「從 Google 試算表 讀取資料至 App Inventor」的進階應用,會使用 Visualization API 簡易呼叫法 讀取資料,但資料表是新建立的,跟之前不同。

1. 首先至 Google 試算表建立一個新的試算表

於試算表頁面的左下方,點選加號按鈕新增工作表。

在新的工作表中新增一些資料

資料新增完後,於頁面右上方,點選「共用」按鈕,設定成「知道連結的使用者」可以讀取到資料。(不用複製連結)

接著要來複製試算表網址
2. 把滑鼠移到第一個工作表後點選,將網址複製到記事本,複製完後把第二個工作表的網址,也複製到記事本。

我們要透過不同的 gid 編號,去讀取各個工作表的內容。
網址的 d/ 到 /edit 之間是試算表的編號,可以先單獨複製出來,等等設定網址會用到。

接著要來製作 App
3. 開啟 App Inventor 並新增一個專案「GSheetsRead」
所需元件如下:

切換到程式設計
首先建立以下變數:

變數 gid 存放妳剛剛複製到記事本的 gid 編號
變數 URL 為網路元件的網址
網址格式為:
https://spreadsheets.google.com/tq?tqx=out:csv&key=1DtWMAawXfgdo0nwi9T7uTKBxWZX0Q14SM2Z3aQ-TIxo&gid=

再來拖拉按鈕被點選的方塊

太簡單了!就不特別講了
最後拖拉當網路元件讀取到資料的方塊

太簡單了!就不~~特別講了………
App 到此製作完畢!
完整程式拼圖

專案 aia 檔案下載
App 範例執行
如果覺得文章內容還不錯的話,麻煩請幫我點個讚!感謝
可以多點幾次喔~~
第一次點讚需使用 Google 或 Facebook 帳號註冊

