simple node module to transform all worksheets in a google spreadsheet into a 2 dimensional array accessible via x (=columns) and y (=rows) coordinates
npm install google-spreadsheets-to-2d-array
// configuration includes:
// - credentials for your google service account
// - number of rows to extract - otherwise all rows are extracted
// - number of columns to extract - otherwise all cols are extracted
// - logger: an instance of a logging tool e.g. winston.js - otherwise console will be used
var config = {
credentials: require('./credentials.json'),
rows: 20,
cols: 10
};
var sheet = require('google-spreadsheets-to-2d-array')(config);
var id = '<your-spreadsheet-id>';
// load a spreadsheet
sheet.load(id)
.then(function(r){
console.log(r.sheet(0).get(0,1));
console.log(r.sheet(1).get(0,1));
console.log(r.sheet(0).data.length);
})
.catch(function(err){
console.error(err);
});
// load, change and save a spreadsheet
sheet.load(id)
.then(function(r){
// make changes to worksheet 1
r.sheet(0).set(0,10,'Value 1');
r.sheet(0).set(2,10,'Value 2');
return sheet.save(id, r);
})
.then(function(r){
console.log('success');
})
.catch(function(err){
console.error(err);
});
Thanks to https://github.com/theoephraim/node-google-spreadsheet for doing the real work.
- v0.1.0 added saving capability, renamed #extract() to #load()
- v0.0.1 basic implementation