@altangent/lib-sheets
TypeScript icon, indicating that this package has built-in type declarations

0.14.0 • Public • Published

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:

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

Readme

Keywords

Package Sidebar

Install

npm i @altangent/lib-sheets

Weekly Downloads

1

Version

0.14.0

License

MIT

Unpacked Size

42.1 kB

Total Files

40

Last publish

Collaborators

  • bmancini55
  • camray