Quickly publish a set of unstructured JSON objects into a Google spreadsheet that you specify.
const O2GS = require('object-to-google-spreadsheet');
// require your Google json credentials file
const creds = require('./creds');
const myReport = new O2GS(creds, '<Your docKey here>');
const options = {
sheetName: 'My Awesome Report',
rowName: 'person', // (optional) the key name of the base of your rows
properties: 'properties', // (optional) the field containing your base's properties
a1Field: 'details', // (optional) the value of the A1 field
sort: true, // (optional) sort fields row alphabetically
removeBase: false // (optional) if true, the base column won't be rendered in the sheet
};
// input must be an array of your objects
const docs = [
{
person : "John",
properties : {
Age: 25,
Address : "16 main st."
}
},
{
person : "Jane",
properties : {
Age : 24,
Hobbies : ["swimming", "Javascripting"]
}
}
];
// push your object to the sheet
myReport.push(docs, options)
.then(result => console.log(result))
.catch(err => console.log(err));
// using async/await
(async ()=> {
try {
await myReport.push(docs, options);
} catch(err) {
console.log(err);
}
})();
- Every Google Sheet has a unique key in the URL
- https://docs.google.com/spreadsheets/d/{docKey}/
- Go to the Google Developers Console
- Select or Create Project
- Dashboard > Enable APIs and Services > Enable the Drive API for your project
- Credentials > Create Service Account Key
- Select Json Key type and save the downloaded json file to your project
- Once you have created the services account, you will have an email [email protected]. Go to your Google Sheets file and shared the edit permission to the email address.
- For more details, please refer to https://www.npmjs.com/package/google-spreadsheet
- https://developers.google.com/google-apps/spreadsheets/
- https://www.npmjs.com/package/google-spreadsheet
- https://www.npmjs.com/package/array-to-google-sheets
This project is licensed under the MIT License and built for OneMeter.com