mirror of
https://github.com/bellingcat/google-apps-script.git
synced 2026-06-11 12:58:35 +03:00
37 lines
1.3 KiB
Markdown
37 lines
1.3 KiB
Markdown
### 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
|
|
```gs
|
|
// 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](SheetHelper.gs) for more info
|