林何家
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # 使用 google excel 當作簡易資料庫 link8fish@gmail.com [線上前端網址](https://funfish22.github.io/google_excel/index.html) [excel表格](https://docs.google.com/spreadsheets/d/1IBSxhno-sPN6vaDLhZHQTRvwFRCfHrcyxXcVO4_QgT0/edit#gid=0) 1. 創立表格,工具->指令碼編輯器(https://i.imgur.com/JdhPIPe.png) ![](https://i.imgur.com/JdhPIPe.png) 2. 指令碼編輯器(https://i.imgur.com/p6lRtYv.png) ![](https://i.imgur.com/p6lRtYv.png) 程式一開始將 myFunction 改為 doGet or doPost,doGet就是前端API用get,doPost就是前端用post 1. 一開始先將 google表格分享,SpreadsheetApp.openById("1IBSxhno-sPN6vaDLhZHQTRvwFRCfHrcyxXcVO4_QgT0"),ID就輸入excel表格的一串文字,如圖紅底線。 ![](https://i.imgur.com/Blztlo4.png) 2. 兩種方法讀取excel的工作表,用數字或者直接指定表格工作表名稱。 1. SpreadSheet.getSheets()[0] 工作表1 2. SpreadSheet.getSheets()[1] 工作表2 3. SpreadSheet.getSheetByName('工作表1') ![](https://i.imgur.com/WMWzx6V.png) 3. Sheet.getLastRow() 讀取最後一列,Sheet.getLastColumn(),讀取最後一欄。 4. 然後其他新增,刪除,查詢,都可用JS寫法寫。 5. 接下來就可以部屬了,點選右上角的部屬,新增部屬作業,設定選網頁應用程式,執行身分選擇自己,誰可以存取選所有人,然後按下部屬按鈕即可,然後將網址複製一下,供前端使用。 ![](https://i.imgur.com/1KrHKRV.png) ![](https://i.imgur.com/Q94lKmk.png) ![](https://i.imgur.com/ZQQ3fMN.png) 6. 實作新增、刪除、查詢功能 7. 當程式寫法,可以創一個 function,來做偵錯,執行成功,查看表格也新增成功 ![](https://i.imgur.com/Vk66mdd.png) ![](https://i.imgur.com/M5aRL1P.png) ```javascript= function debug() { var a = doPost( { parameter : { name: 1, phone: 2, adress : 2, action: 'add' } }); } ``` ```javascript= function doGet() { //請輸入自己的sheet id var SpreadSheet = SpreadsheetApp.openById("1IBSxhno-sPN6vaDLhZHQTRvwFRCfHrcyxXcVO4_QgT0"); var Sheet = SpreadSheet.getSheets()[0]; // SpreadSheet.getSheets()[0] 工作表1 SpreadSheet.getSheets()[1] 工作表2 // var SheetName = SpreadSheet.getSheetByName(name); var LastRow = Sheet.getLastRow(); // 最後一列 var LastCol = Sheet.getLastColumn() // 最後一欄 console.log('LastRow', LastRow) var data = []; var listAll = Sheet.getSheetValues(1, 1, LastRow, LastCol); //第一列,第一欄,最後一列 for (var i=0; i < listAll.length; i++) { data.push({ data: listAll[i], index: i }); } // 回傳陣列 return ContentService.createTextOutput(JSON.stringify(data)).setMimeType( ContentService.MimeType.JSON ); } function doPost(e) { //取得參數 var params = e.parameter; var name = params.name; var phone = params.phone; var adress = params.adress; var action = params.action; var searchName = params.searchName; var deleteId = params.deleteId; //sheet資訊 //請輸入自己的sheet id var SpreadSheet = SpreadsheetApp.openById("1IBSxhno-sPN6vaDLhZHQTRvwFRCfHrcyxXcVO4_QgT0"); // 試算表的ID var Sheet = SpreadSheet.getSheets()[0]; // SpreadSheet.getSheets()[0] 工作表1 SpreadSheet.getSheets()[1] 工作表2 var LastRow = Sheet.getLastRow(); var LastCol = Sheet.getLastColumn() console.log('LastRow', LastRow) // 最後一列 console.log('LastCol', LastCol) // 最後一欄 // 使用帶入不同的參數,做不同的事情 // 新增資料 if(action === 'add') { //存入資訊 //getRange(LastRow+1, 1) // 最後一列 + 1,存入的欄位 Sheet.getRange(LastRow+1, 1).setValue(name); // 最後一列,第一欄新增姓名資料 Sheet.getRange(LastRow+1, 2).setValue(phone); // 最後一列,第一欄新增電話資料 Sheet.getRange(LastRow+1, 3).setValue(adress); // 最後一列,第一欄新增地址資料 //回傳資訊 return ContentService.createTextOutput("成功"); } // 搜尋資料 if(action === 'search') { var data = []; var listAll = Sheet.getSheetValues(1, 1, LastRow, LastCol); //第一列,第一欄,最後一列,第3欄 for (var i=0; i < listAll.length; i++) { if(listAll[i][0].indexOf(searchName) === 0) { data.push({ data: listAll[i], index: i }); console.log('data', data) } } // 回傳陣列 return ContentService.createTextOutput(JSON.stringify(data)).setMimeType( ContentService.MimeType.JSON ); } if(action === 'delete') { //刪除 Sheet.deleteRow(deleteId); // 刪除第幾列整列資料 //回傳資訊 return ContentService.createTextOutput("成功"); } return ContentService.createTextOutput("失敗"); } ``` 8. 前端,api網址,就是剛剛部屬複製的網址(https://i.imgur.com/IqvE8On.png) ![](https://i.imgur.com/IqvE8On.png) ```javascript= function searchAll() { $.ajax({ url: "https://script.google.com/macros/s/AKfycbwa-x0rnFLSIZ4OxBhzDeFzdetQ0qdMcM4S2L4e_1Nil7WFwd2QsR7HSK620vqjj_37/exec", type: "GET", success: function(response) { response.forEach((element, index) => { allDom += `<div>第${index + 1}筆,姓名:${element.data[0]},電話:${element.data[1]},地址:${element.data[2]}</div>` }) all.innerHTML = allDom }, }); } ```

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully