Skip to content

Utility for reading & writing tables in Google Sheets (Google Apps Script)

License

Notifications You must be signed in to change notification settings

dtrlanz/sheetable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sheetable

A utility for reading & writing tables in spreadsheets using Google Apps Script


Install

npm install @dtrlanz/sheetable

Usage

The following examples assume you are building your project with a bundler that allows you to import modules (e.g., @dtrlanz/gas-bundler).

For an example setup, see the server-side code, client-side HTML, and build script of the included test app.

Server-side code

Import SpreadsheetServer and add the following top-level function to your code:

import { SpreadsheetServer } from "@dtrlanz/sheetable";

function processSpreadsheetRequest(req) {
    return new SpreadsheetServer().processRequest(req);
}

If you want to limit client access to a specific spreadsheet, pass that to the SpreadsheetServer constructor:

const spreadsheet = SpreadsheetApp.openByUrl(/* spreadsheet url */);

function processSpreadsheetRequest(req) {
    return new SpreadsheetServer(spreadsheet).processRequest(req);
}

Note: As always, if you are using a bundler that performs tree-shaking, you will need to ensure your top-level functions are not eliminated. You can do this by assigning to globalThis:

globalThis.processSpreadsheetRequest = processSpreadsheetRequest;

Client-side code

Import Table and create a class that defines the records in your table. You can then create new table using Table.create() or open a table from an existing spreadsheet using Table.open().

import { Table } from "@dtrlanz/sheetable";

class Person {
    firstName = "";
    lastName = "";
    dob = new Date(0);
}

const people = Table.create(Person);

For further customization, you will probably want to import some decorators as well:

import { Table, title, index } from "@dtrlanz/sheetable";

class Person {
    @index
    @title("ID")
    id = 0;

    @title("First name")
    firstName = "";

    @title("Last name")
    lastName = "";

    @title("Date of birth")
    dob = new Date(0);
}

const people = Table.create(Person);

Attribution & Disclaimer

Google and Google Sheets are trademarks of Google LLC. This project is not endorsed by or affiliated with Google in any way.

License

Sheetable is released under the MIT license.

About

Utility for reading & writing tables in Google Sheets (Google Apps Script)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published