Skip to content

saffiullahfahim/sheet-to-html

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Google Sheet to HTML

Hits

Init Google Apps Script

First we need to deploy google apps script. Copy code below and replace to which sheet you want to get data.

Code.js

function doGet() {
  const sheetName = "<Sheet Name>";

  try {
    let now = new Date();

    const ss = SpreadsheetApp.getActive();
    const sheet = ss.getSheetByName(sheetName);
    const range = sheet.getDataRange();
    const data = range.getValues();

    return ContentService.createTextOutput(
      JSON.stringify({
        data: data,
        time: new Date() - now,
      })
    );
  } catch (err) {
    return ContentService.createTextOutput(
      JSON.stringify({
        error: err.message,
      })
    );
  }
}

Add Javascript in your html code

<script src="https://saffiullahfahim.github.io/sheet-to-html/sheetToHtml.js"></script>

Use Code and Get Data

// init SheetToHtml
new SheetToHtml({
  scriptUrl: "..." // Google Apps Script Link i.e https://script.google.com/macros/s/AKfycbz3Cn6900c9_d9KK7rXUU4w_CuCd98wt87oCn25gUr7COjTVx1DeZ5gRH84BHEqRxhz/exec
  callBack: showData, // callback which run after get sheet data
});

function showData(sheetData) {
  let cellA1Data = sheetData.getData("A1"); // get data by A1 Notation
  let cellA2Data = sheetData.getData("A2"); // get A2 cell data
  let cellB2Data = sheetData.getRowColumn("B2"); // get row = 1, column = 1 data

  // ... next what you want with these data
}