@altangent/lib-sheets
v0.14.0
Published
Data store for Google sheets
Downloads
121
Readme
Sheets
Basic client for reading and writing to Google Sheets from desktop applications
Examples
You need to create a project and credentials via these instructions:
- https://developers.google.com/workspace/guides/create-project
- https://developers.google.com/workspace/guides/create-credentials
import { SheetsClient } from "@altangent/lib-sheets";
// obtained from google
const credentials = {};
const scopes = ["https://www.googleapis.com/auth/spreadsheets"];
// construct a client
const client = new SheetsClient(credentials, scopes);
// obtain the code request URL
console.log(client.requestCodeUrl());
You can then navigate to the generated URL and grant access which will generate a code. This that is used to obtain a token.
const code = "<OBTAINED FROM GOOGLE>";
// request the token
client.requestToken(code).then(console.log).catch(console.error);
You can now use the token in subsequent requests.
const client = new SheetsClient(credentials, scopes, token);
// query a range
client
.getRange("11111111111111111111111111111111111111111111", "Sheet1!A2:F")
.then(console.log)
.catch(console.error);
// update a range
client
.setRange("11111111111111111111111111111111111111111111", "Sheet1!N50:P51", [
["1", "2", "3"],
["4", "5", "6"],
])
.then(console.log)
.catch(console.error);
More info:
https://developers.google.com/sheets/api/ https://developers.google.com/sheets/api/quickstart/nodejs
https://developers.google.com/sheets/api/samples/reading https://developers.google.com/sheets/api/reference/rest/v4/ValueRenderOption https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/get