Files
google-apps-script/gsheets-helper
Miguel Sozinho Ramalho cd147aad0f Update README.md
2023-01-11 12:27:25 +00:00
..
2023-01-11 12:27:25 +00:00
2023-01-11 12:06:24 +00:00

Goal

This class makes it easy to read/write from a google sheet instance via an API, it's aimed at tabular data that has a header row with names.

Features:

  • read/write tabular data as cell/column
  • lock/unlock sheet
  • read and handle sheet protections
  • find next empty row in table

How

// be sure to have the sheet-helper class available in another file or via addons

let sh = new SheetHelper("id-of-gsheets", "worksheet-name", "header index - starts at 1", "loadData - if true will fetch data", "colNamer in case you want to refer to");
// id - the id of the google sheets doc
// sheetName - the worksheet tab name
// headerIndex - 1-based which row has the table header
// loadData - true to fetch all data from the start
// colNamer - custom function in case you want to customize how to refer to the header names, defaults to identity: (x) => x
let sh = new SheetHelper(id, sheetName, headerIndex, loadData, colNamer);


// example locking and unlocking for read/write operations
sh.lock();{
  // operations while locked, eg write an entire column of values from the next empty row
  
  let newLinks = ["a", "b", "c"];
  let insertAtRow = sh.newRowIndex()
  sh.setCol(insertAtRow, "linksColum", newLinks);
  
} sh.unlock();

check the source code comments for more info