stream-google-spreadsheet
Read Google spreadsheet rows as a stream of either JSON or Vinyl objects.
Ideally I would use google-worksheet-stream but I wasn't able to get it working so I just moved on. I'll revisit that library before adding any more features to this one though, just in case this one can be discarded.
Usage
The module exposes two functions, each of which returns a Highland stream. The first function, available as the main export
, returns each row of the spreadsheet as a JSON object:
var sheetStream = ; ;
The output might look something like this:
The second function wraps these JSON rows in Vinyl objects and is available as src()
off the main export:
var gulp = ;var sheets = ;var es = ; gulp;
The Vinyl objects returned from src()
will have their path
set to the url
value in the data, the data
property set to the JSON returned, and the contents
property set to a Buffer
version of the JSON:
Whichever function is used, the parameters are the same:
The glob
parameter contains one or more spreadsheet keys.
The opt
parameter provides the keys used to log in (opt.clientEmail
and opt.privateKey
), as well as an optional indicator of which worksheet should be loaded (opt.wsNum
).
Full Example
To illustrate, here is a complete example that takes rows in a spreadsheet and inserts them into an ElasticSearch index:
var gulp = ;var sheets = ;var es = ; var env = processenv; gulp;
Column Names
A column name in a spreadsheet becomes the name of a property in the resulting JSON, which makes for a very convenient mapping. However, the property names are always lowercase, which is not so convenient. As a simple workaround we pass the object keys through LoDash's camelCase
function, which means that if we want properties that are camel case in the resulting JSON then we need only use hyphens in the column names in the source spreadsheet.