
Security News
rv Is a New Rust-Powered Ruby Version Manager Inspired by Python's uv
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
node-sheets
Advanced tools
Read rows from google spreadsheet with google's sheets api.
$ npm install node-sheets --save
$ yarn add node-sheets
Example to retrieve data from this google spreadsheet using ES7 async/await.
import Sheets from 'node-sheets';
try {
const gs = new Sheets('1amfst1WVcQDntGe6walYt-4O5SCrHBD5WntbjhvfIm4');
const authData = require('someGoogleCredentials.json'); // authData = { client_email, private_key }
await gs.authorizeJWT(authData);
const table = await gs.tables('Formats!A1:E3');
console.log(table.headers);
console.log(table.formats);
console.log(table.rows);
} catch (err) {
console.error(err);
}
You can also use the lib with Promises.
import Sheets from 'node-sheets';
const gs = new Sheets('1amfst1WVcQDntGe6walYt-4O5SCrHBD5WntbjhvfIm4');
const authData = require('someGoogleCredentials.json'); // authData = { client_email, private_key }
gs.authorizeJWT(authData)
.then(() => gs.tables('Formats!A1:E3'))
.then((table) => {
console.log(table.headers);
console.log(table.formats);
console.log(table.rows);
})
.catch((err) => {
console.error(err);
});
If you want to use this with require
you need to import the default
:
const Sheets = require('node-sheets').default;
Sheets.tables(string|object|array)
Returns tabular sheet data for the specified ranges. This method accepts three distinct type of arguments: string, object and array.
If a string argument is specified, it defines the name of the range (A1 notation) to be retrieved from the spreadsheet.
The return model is a SheetTable
object.
If an object argument is specified, we expect to have an object with name
and (optional) range
properties.
The return model is a SheetTable
object.
When the argument is an array, we want to retrieve table values for several sheets.
The return model is an array of SheetTable
objects.
SheetTable
response schemaThe .tables()
method returns SheetTable objects that contains tabular data for a sheet.
Header 1 | Header 2 | Header 3 |
---|---|---|
row 1 text | $0.41 | 3.00 |
... | ... | ... |
const table = await gs.tables('Formats');
{
title: 'Formats', // name of the sheet/table
headers: ['Header 1', 'Header 2', 'Header 3'], // name of the headers (1st row)
formats: [ // array with information regarding cell format
{ numberFormat: { type: 'NONE' } },
{ numberFormat: { type: 'CURRENCY', pattern: '"$"#,##0.00' } },
{ numberFormat: { type: 'NUMBER', pattern: '#,##0.00' } } ]
rows: [ // rows contains the values for 2nd row ahead
{ // Each row object has:
'Header 1': { value: 'row 1 text', stringValue: 'row 1 text' },
'Header 2': { value: 0.41, stringValue: '$0.41' },
'Header 3': { value: 3, stringValue: '3.00' }
},
{ ... },
{ ... }
]
}
Sample access to the value of col 'Header 2' of first row:
const currencyValue = table.rows[0]['Header 2'].value; // 0.41
Note: Formats are retrieved from first data row.
const sheet = await gs.tables('main'); // ranges = ['main']
const sheet = await gs.tables('A100'); // ranges = ['A100'] - that is the cell A100 and not the sheet A100
const sheet = await gs.tables({ sheet: 'main' }); // ranges = ['main!A:ZZZ']
const sheet = await gs.tables({ sheet: 'main', range: 'A1:B4' }); // ranges = ['main!A1:B4']
const sheets = await gs.tables([
{ sheet: 'main' },
{ sheet: 'D001', range: 'A1:D3' },
{ sheet: 'D002' },
]); // ranges = ['main!A:ZZZ', 'D001!A1:D3', 'D002!A:ZZZ']
Parsing as a cell or a named range will take precedence over a sheet name when using string argument. More info here.
node-sheets offers two authentication methods.
With JWT token (.authorizeJWT(auth [, scopes])
) using private_key
and client_email
, and also allowing to set auth scopes. The default auth scope is https://www.googleapis.com/auth/spreadsheets.readonly.
With api key (.authorizeApiKey(apikey)
) using an api key you have created in the google developers console.
Sheets.getLastUpdateDate()
Returns a ISO_8601 compatible string with the last update date of the spreadsheet. This can be used to check if a re-fetch is needed.
Sheets.getSheetsNames()
Returns a list with all the names of the sheets in the spreadsheet.
You can check the /test/index.js
file for examples.
This library is licensed under MIT. Full license text is available in LICENSE.
We appreciate any contribution to this project. We keep a list of features and bugs in the issue tracker.
FAQs
Utility Wrapper for Google Spreadsheets
The npm package node-sheets receives a total of 348 weekly downloads. As such, node-sheets popularity was classified as not popular.
We found that node-sheets demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.
Security News
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.