{"id":25208245,"url":"https://github.com/1010code/googlesheetapi","last_synced_at":"2026-06-23T16:31:41.214Z","repository":{"id":118676310,"uuid":"292839155","full_name":"1010code/GoogleSheetAPI","owner":"1010code","description":null,"archived":false,"fork":false,"pushed_at":"2020-09-04T15:44:25.000Z","size":799,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-19T14:00:58.437Z","etag":null,"topics":["gas","gas-api"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/1010code.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2020-09-04T12:12:06.000Z","updated_at":"2020-09-04T15:44:27.000Z","dependencies_parsed_at":null,"dependency_job_id":"77188c73-d9b5-40c0-a02b-39bd62b3b0d8","html_url":"https://github.com/1010code/GoogleSheetAPI","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/1010code/GoogleSheetAPI","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1010code%2FGoogleSheetAPI","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1010code%2FGoogleSheetAPI/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1010code%2FGoogleSheetAPI/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1010code%2FGoogleSheetAPI/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/1010code","download_url":"https://codeload.github.com/1010code/GoogleSheetAPI/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1010code%2FGoogleSheetAPI/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34698687,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-23T02:00:07.161Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gas","gas-api"],"created_at":"2025-02-10T12:19:09.770Z","updated_at":"2026-06-23T16:31:41.208Z","avatar_url":"https://github.com/1010code.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# 使用 Google App Script 將 Google 試算表變成資料庫\n## Google App Script\n此篇教學使用 Google App Script，將前端的表單資料寫入雲端硬碟中的 Google Sheets 當中。透過此方法我們就不需要建立後端資料庫來儲存這些表單資料。\n\n## 建立 Google 雲端試算表\n首先開啟[雲端硬碟](https://drive.google.com/)建立一個空白的試算表。在空白處點選右鍵即可新增一個Excel試算表。\n\n![](./screenshot/img20200804-1.png)\n\n這邊範例為GAS表單測試。可以在第一行寫入你要收集資料的欄位名稱，這裏的範例是要搜集使用者的`姓名`和`信箱`。\n\n![](./screenshot/img20200804-2.png)\n\n## 建立 Google App Script\n首先可以先進入到 [Google Apps Script](https://script.google.com/home/start) 服務(以下簡稱 GAS)。服務介面類似於 Google 雲端硬碟。在這邊就可以撰寫你的 GAS 函式並部署執行。簡單來說 GAS 是一種serverless服務，即 Google 會在服務背後提供伺服器運行。使用者只要撰程式碼並部署，即可在一個獨立的伺服器上運行你的程式。\n\n![](./screenshot/img20200804-3.png)\n\n點選新的空白專案就會開啟 GAS 的編輯界面。就可以來撰寫API囉，首先函數名稱設為 `doPost` 代表 API method 爲 Post。接著我們要使用 SpreadsheetApp 類別初始化試算表，在圖片灰色框框輸入你的試算表 id。id 就是 Google Sheet 網址列 https://docs.google.com/spreadsheets/d/ 以後至 edit 中間的代碼。\n\n![](./screenshot/img20200804-4.png)\n\n```js\nfunction doPost(e) {\n  // 取得輸入參數\n  let params = e.parameter; \n  let name = params.name;\n  let mail = params.mail;\n \n  // 初始化試算表\n  let SpreadSheet = SpreadsheetApp.openById(\"輸入你的試算表 id\");\n  let Sheet = SpreadSheet.getSheets()[0]; // 指定第一張試算表\n  let LastRow = Sheet.getLastRow(); // 取得最後一列有值的索引值\n\n  // 寫入試算表\n  Sheet.getRange(LastRow+1, 1).setValue(name);\n  Sheet.getRange(LastRow+1, 2).setValue(mail);\n  \n  // 回傳結果\n  return ContentService\n  .createTextOutput(JSON.stringify({ result: '成功', version: '1.0' }))\n      .setMimeType(ContentService.MimeType.JSON); \n}\n```\n\n程式撰寫完畢後就能部署我們的 GAS。點選發布→部署為網頁應用程式。將具有應用程式存取權的使用者改爲 `任何人，甚至是匿名使用者`。\n\n![](./screenshot/img20200804-6.png)\n\n## 使用 Postman 測試\nPostman 是一個能夠模擬 HTTP Request 的工具能夠讓你簡單快速的測試你的 API。此工具內建包含很多 HTTP 的請求方式，例如常見的的 GET(取得)、POST(新增)、PUT(修改)、DELETE(刪除)。GAS 發布後會給你一串 API 網址，這個網址就能拿來做存取。\n\n![](./screenshot/img20200804-5.png)\n\n![](./screenshot/img20200804-7.png)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F1010code%2Fgooglesheetapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F1010code%2Fgooglesheetapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F1010code%2Fgooglesheetapi/lists"}