Reading Data From Google Sheets to HTML Using JavaScript and Apps Script



Reading Data From Google Sheet | Google Sheet to JSON and JSON to HTML | JavaScript and Apps Script

In today's video you will learn about How to read and display data from Google Sheet.

AppsScript Code


const ss = SpreadsheetApp.openByUrl("Your google sheet url")
const sheet = ss.getSheetByName("Sheet1")
function doGet(e){
  let obj = {};
  let data = sheet.getDataRange().getValues()
  obj.content = data;
return ContentService.createTextOutput(JSON.stringify(obj)).setMimeType(ContentService.MimeType.JSON)

}

Deploy your appsscript project and copy the API endpoint URL.

HTML, JavaScript Code


<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        tr {
            background-color: lightGrey;
        }
        
        tr:nth-child(2n) {
            background-color: grey;
        }
    </style>
</head>

<body>
    <table></table>
    <script>
        fetch('paste your api end point url here')
            .then(res => res.json())
            .then(data => {
                let tr = data.content.reduce((prev, cur) => {
                    let td = cur.map(e => `<td>${e}</td>`)
                    return prev + `<tr>${td.join("")}</tr>`
                }, "\r")
                document.querySelector("table").innerHTML = tr;
                
            });
    </script>
</body>

</html>

Keywords :

dynamically display data from google sheets into a web app
spreadsheet to html table
google html page
google apps script html table
spreadsheet in html
google apps script html css
google sheet to website free
google apps script html form submit
how to connect html form to google sheets
get data from google sheets to html
how to create a google page in html
google sheet page setup
how to create google search page in html


More Posts For You!


5 More HTML Tricks For You

5 HTML Tricks That You Can Use To Enhance Your Web Pages

Effortlessly Convert Excel to JSON with JavaScript: Streamline Your Data Management with Sheet Js

Integrating OCR Capabilities into Web Applications with JavaScript and AppScript

Efficient Text Extraction from PDFs: Implementing OCR with JavaScript and AppScript

Build a CRUD Application Using Google Sheets as Database with HTML, CSS, and JavaScript

Integrating OpenAI with Google Sheets using AppScript for Automated Responses

Upload Images to Google Drive and Google Sheets from HTML File Input: A Complete JavaScript and AppScript Guide

Convert HTML and CSS to PDF with JavaScript Using HTML2PDF.js

Create a Functional Contact Form Using HTML, CSS, JavaScript, and Google AppScript

Build a CRUD App Using HTML, CSS, JavaScript, and IndexedDB API

Reading Data From Google Sheets to HTML Using JavaScript and Apps Script

PrevNext