Simple Sheets Writer
This package is deprecated in favor of simple-sheets
, which combines this with the simple-sheets-reader
API
Writes Google Sheets data, perfect for sheets populated by Google Forms. This is a wrapper for the very powerful-yet-overwhelming official Sheets API.
Authenticates via a Google Service Account by passing in the client_email
and private_key
values provided by the .json
file that Google Service Accounts generate. See service-account-credentials.json for an example.
API
simple-sheets-writer
exports an object with two functions, updateRows
and addRows
. updateRows
takes the following arguments:
;
data
is an array of objects, following the following format:
range: "A2:A" values: "A" "B"
options
include:
spreadsheetId
(required): The ID of the Google sheet, which is the long string in the URL of the pageclientEmail
(required): The authorizedclient_email
for your service account (remember to add permissions for this email to your sheet!)privateKey
(required): the authorizedprivate_key
for your service accountvalueInputOption
: Whether input should be taken literally ("RAW"
), or as if a user entered them ("USER_ENTERED"
, default)
It returns a count of modified rows:
updatedRows: 1
addRows
has the following parameters:
;
range
is an A1 range (eg "A2:A") that will be searched to find something table-like to append to the end of.
data
is an array of arrays of values to add:
"column 1" "column 2" "column 1" "column 2"
options
include:
spreadsheetId
(required): The ID of the Google sheet, which is the long string in the URL of the pageclientEmail
(required): The authorizedclient_email
for your service account (remember to add permissions for this email to your sheet!)privateKey
(required): the authorizedprivate_key
for your service accountvalueInputOption
: Whether input should be taken literally ("RAW"
), or as if a user entered them ("USER_ENTERED"
, default)
It returns an object with the count of modified rows:
updatedRows: 1
Usage
const updateRows addRows = ; // {updatedRows: 4}; // {updatedRows: 2};
Look at the Google Sheets batchUpdate
API Docs and the Google Sheets append
API Docs for more information.
Tests
npm test
Upgrading to 2.0
- Credentials need to be passed in, rather than read from the environment