All Projects → urbancups → node-sheets

urbancups / node-sheets

Licence: MIT License
read rows from google spreadsheet with google's sheets api

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to node-sheets

S2
⚡️ Practical analytical Table rendering core lib.
Stars: ✭ 818 (+5012.5%)
Mutual labels:  spreadsheet, sheet
Active importer
Define importers that load tabular data from spreadsheets or CSV files into any ActiveRecord-like ORM.
Stars: ✭ 333 (+1981.25%)
Mutual labels:  tabular-data, spreadsheet
React Datasheet
Excel-like data grid (table) component for React
Stars: ✭ 4,866 (+30312.5%)
Mutual labels:  spreadsheet, sheet
Tui.grid
🍞🔡 The Powerful Component to Display and Edit Data. Experience the Ultimate Data Transformer!
Stars: ✭ 1,859 (+11518.75%)
Mutual labels:  tabular-data, spreadsheet
Social-Media-Monitor
Automatically monitor and log fan counters from social media(Facebook Pages, Twitter, Instagram, YouTube, Google+, OneSignal, Alexa) using APIs to Google Spreadsheet. Very useful for website admins and social media managers.
Stars: ✭ 36 (+125%)
Mutual labels:  google-spreadsheet, spreadsheet
google-spreadsheet-cli
📊 CLI for reading and writing data into Google Spreadsheet
Stars: ✭ 51 (+218.75%)
Mutual labels:  google-spreadsheet, spreadsheet
Visidata
A terminal spreadsheet multitool for discovering and arranging data
Stars: ✭ 4,606 (+28687.5%)
Mutual labels:  tabular-data, spreadsheet
Luckysheet
Luckysheet is an online spreadsheet like excel that is powerful, simple to configure, and completely open source.
Stars: ✭ 9,772 (+60975%)
Mutual labels:  google-spreadsheet, spreadsheet
OpenWebSheet
OpenSource Web based spreadsheet
Stars: ✭ 30 (+87.5%)
Mutual labels:  spreadsheet, sheet
wowspreadsheet
World of Warcraft character tracking spreadsheet for Google Docs
Stars: ✭ 37 (+131.25%)
Mutual labels:  spreadsheet
citybook
Create a resource directory from a contact spreadsheet.
Stars: ✭ 21 (+31.25%)
Mutual labels:  google-spreadsheet
sheet2dict
Simple XLSX and CSV to dictionary converter
Stars: ✭ 206 (+1187.5%)
Mutual labels:  spreadsheet
react-gridsheet
React component like SpreadSheet
Stars: ✭ 121 (+656.25%)
Mutual labels:  spreadsheet
openharmony-sheet
📊从零开始使用华为鸿蒙 OpenHarmony 开发游戏和表格渲染引擎
Stars: ✭ 132 (+725%)
Mutual labels:  sheet
anita
Anita is a private, no-server, powerful and fully customizable data management solution, open source and free of charge. With Anita you can organize any number of things you want to track, with one of our pre-configured Anita Templates or by defining your own custom data structure. Anita can handle many different data types, and can present your…
Stars: ✭ 30 (+87.5%)
Mutual labels:  spreadsheet
spreadsheet-to-json
Convert Google Spreadsheets to JSON using Javascript
Stars: ✭ 53 (+231.25%)
Mutual labels:  google-spreadsheet
Tabula
🈸 Pretty printer for maps/structs collections (Elixir)
Stars: ✭ 85 (+431.25%)
Mutual labels:  tabular-data
fast-formula-parser
Parse and evaluate MS Excel formula in javascript.
Stars: ✭ 341 (+2031.25%)
Mutual labels:  spreadsheet
account
📚️ ➕ 🔢 Tell little stories with numbers
Stars: ✭ 94 (+487.5%)
Mutual labels:  spreadsheet
gulp-texturepacker
Gulp plugin for TexturePacker
Stars: ✭ 12 (-25%)
Mutual labels:  sheet

node-sheets

Read rows from google spreadsheet with google's sheets api.

styled with prettier

Installation

$ npm install node-sheets --save
$ yarn add node-sheets

Usage

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;

API

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.

String

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.

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.

Array

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 schema

The .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.

Sample usage

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']

Caveat

Parsing as a cell or a named range will take precedence over a sheet name when using string argument. More info here.

Authentication

node-sheets offers two authentication methods.

  1. 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.

  2. 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.

Examples

You can check the /test/index.js file for examples.

License

This library is licensed under MIT. Full license text is available in LICENSE.

Contributing

We appreciate any contribution to this project. We keep a list of features and bugs in the issue tracker.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].