All Projects → theoephraim → Node Google Spreadsheet

theoephraim / Node Google Spreadsheet

Licence: unlicense
Google Sheets API (v4) wrapper for Node.js

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Node Google Spreadsheet

Gspread Pandas
A package to easily open an instance of a Google spreadsheet and interact with worksheets through Pandas DataFrames.
Stars: ✭ 226 (-83.49%)
Mutual labels:  google-sheets, google
Firebase
[DEPRECATED] Unofficial Carthage support for Firebase libraries
Stars: ✭ 99 (-92.77%)
Mutual labels:  google
Image search
Python Library to download images and metadata from popular search engines.
Stars: ✭ 86 (-93.72%)
Mutual labels:  google
Capacitorgoogleauth
Capacitor plugin for Google Auth. Lightweight & no dependencies.
Stars: ✭ 92 (-93.28%)
Mutual labels:  google
Androidoauth
A simple way to authenticate with Google and Facebook using OAuth 2.0 in Android
Stars: ✭ 88 (-93.57%)
Mutual labels:  google
Godotgoogleservice
Google play service, login, achievements, leaderboard.
Stars: ✭ 94 (-93.13%)
Mutual labels:  google
Svelte Social Auth
Social Auth for Svelte v3
Stars: ✭ 86 (-93.72%)
Mutual labels:  google
Dopamine
Dopamine is a research framework for fast prototyping of reinforcement learning algorithms.
Stars: ✭ 9,681 (+607.16%)
Mutual labels:  google
Pixelslide
A up/down expand arrow anim sample likes Pixel Launcher.
Stars: ✭ 98 (-92.84%)
Mutual labels:  google
Ghunt
🕵️‍♂️ Investigate Google emails and documents.
Stars: ✭ 10,489 (+666.18%)
Mutual labels:  google
Daily Coding Problem
Series of the problem 💯 and solution ✅ asked by Daily Coding problem👨‍🎓 website.
Stars: ✭ 90 (-93.43%)
Mutual labels:  google
Gargle
Infrastructure for calling Google APIs from R, including auth
Stars: ✭ 88 (-93.57%)
Mutual labels:  google
Laravel Sitemap
Create and generate sitemaps with ease
Stars: ✭ 1,325 (-3.21%)
Mutual labels:  google
Runtimes Common
Common tools used by the GCP runtimes.
Stars: ✭ 86 (-93.72%)
Mutual labels:  google
Searchconsoler
R interface with Google Search Console API v3, including Search Analytics.
Stars: ✭ 99 (-92.77%)
Mutual labels:  google
Cloudprober
An active monitoring software to detect failures before your customers do.
Stars: ✭ 1,269 (-7.3%)
Mutual labels:  google
Ot Rtos
OpenThread RTOS, an integration of OpenThread, LwIP, and FreeRTOS.
Stars: ✭ 90 (-93.43%)
Mutual labels:  google
Vpn Libraries
The VPN client libraries provide a reference implementation for a secure, encrypted tunnel for connected devices.
Stars: ✭ 94 (-93.13%)
Mutual labels:  google
Parse Google Docs Json
Authenticates with Google API and parse Google Docs to JSON or Markdown
Stars: ✭ 100 (-92.7%)
Mutual labels:  google
Google Api Nodejs Client
Google's officially supported Node.js client library for accessing Google APIs. Support for authorization and authentication with OAuth 2.0, API Keys and JWT (Service Tokens) is included.
Stars: ✭ 9,722 (+610.15%)
Mutual labels:  google

google-spreadsheet

The most popular Google Sheets API wrapper for javascript

NPM version CircleCI Known Vulnerabilities NPM

  • multiple auth options - service account (w/ optional impersonation), OAuth 2.0, API key (read-only)
  • cell-based API - read, write, bulk-updates, formatting
  • row-based API - read, update, delete (based on the old v3 row-based calls)
  • managing worksheets - add, remove, resize, change title, formatting

Docs site - Full docs available at https://theoephraim.github.io/node-google-spreadsheet

🚨 Google Deprecation Warning - affects older version (v2) of this module 🚨

Google is phasing out their old v3 api, which the older version of this module used. Originally they were going to shut it down on March 3rd 2020, but have pushed that date back to June 2021.

Regardless, please upgrade to the latest version of this module (v3) which uses the newer sheets v4 API


🌈 Installation - npm i google-spreadsheet --save or yarn add google-spreadsheet

Examples

the following examples are meant to give you an idea of just some of the things you can do

IMPORTANT NOTE - To keep the examples concise, I'm calling await at the top level which is not allowed by default in most versions of node. If you need to call await in a script at the root level, you must instead wrap it in an async function like so:

(async function() {
  await someAsyncFunction();
}());

The Basics

const { GoogleSpreadsheet } = require('google-spreadsheet');

// Initialize the sheet - doc ID is the long id in the sheets URL
const doc = new GoogleSpreadsheet('<the sheet ID from the url>');

// Initialize Auth - see more available options at https://theoephraim.github.io/node-google-spreadsheet/#/getting-started/authentication
await doc.useServiceAccountAuth({
  client_email: process.env.GOOGLE_SERVICE_ACCOUNT_EMAIL,
  private_key: process.env.GOOGLE_PRIVATE_KEY,
});

await doc.loadInfo(); // loads document properties and worksheets
console.log(doc.title);
await doc.updateProperties({ title: 'renamed doc' });

const sheet = doc.sheetsByIndex[0]; // or use doc.sheetsById[id] or doc.sheetsByTitle[title]
console.log(sheet.title);
console.log(sheet.rowCount);

// adding / removing sheets
const newSheet = await doc.addSheet({ title: 'hot new sheet!' });
await newSheet.delete();

More info:

Working with rows

// create a sheet and set the header row
const sheet = await doc.addSheet({ headerValues: ['name', 'email'] });

// append rows
const larryRow = await sheet.addRow({ name: 'Larry Page', email: '[email protected]' });
const moreRows = await sheet.addRows([
  { name: 'Sergey Brin', email: '[email protected]' },
  { name: 'Eric Schmidt', email: '[email protected]' },
]);

// read rows
const rows = await sheet.getRows(); // can pass in { limit, offset }

// read/write row values
console.log(rows[0].name); // 'Larry Page'
rows[1].email = '[email protected]'; // update a value
await rows[1].save(); // save updates
await rows[1].delete(); // delete a row

More info:

Working with cells

await sheet.loadCells('A1:E10'); // loads a range of cells
console.log(sheet.cellStats); // total cells, loaded, how many non-empty
const a1 = sheet.getCell(0, 0); // access cells using a zero-based index
const c6 = sheet.getCellByA1('C6'); // or A1 style notation
// access everything about the cell
console.log(a1.value);
console.log(a1.formula);
console.log(a1.formattedValue);
// update the cell contents and formatting
a1.value = 123.456;
c6.formula = '=A1';
a1.textFormat = { bold: true };
c6.note = 'This is a note!';
await sheet.saveUpdatedCells(); // save all updates in one call

More info:

Why?

This module provides an intuitive wrapper around Google's API to simplify common interactions

While Google's v4 sheets api is much easier to use than v3 was, the official googleapis npm module is a giant meta-tool that handles every Google product. The module and the API itself are awkward and the docs are pretty terrible, at least to get started.

In what situation should you use Google's API directly?
This module makes trade-offs for simplicity of the interface. Google's API provides a mechanism to make many requests in parallel, so if speed and efficiency is extremely important to your use case, you may want to use their API directly. There are also several features of their API that are not implemented here yet.

Support & Contributions

This module was written and is actively maintained by Theo Ephraim.

Are you actively using this module for a commercial project? Want to help support it?
Buy Theo a beer

Sponsors

None yet - get in touch!

Contributing

Contributions are welcome, but please follow the existing conventions, use the linter, add relevant tests, add relevant documentation.

The docs site is generated using docsify. To preview and run locally so you can make edits, run npm run docs:preview and head to http://localhost:3000 The content lives in markdown files in the docs folder.

License

This is free and unencumbered public domain software. For more info, see https://unlicense.org.

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