Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kpennell/e79e23b5ecfc73ceb1d13b1a1333b96c to your computer and use it in GitHub Desktop.
Save kpennell/e79e23b5ecfc73ceb1d13b1a1333b96c to your computer and use it in GitHub Desktop.
Google Spreadsheets script for syncing to Firebase
function syncToFirebase () {
var sheet = SpreadsheetApp.getActiveSheet();
var rows = sheet.getDataRange();
var numRows = rows.getNumRows();
var numCols = rows.getNumColumns();
var values = rows.getValues();
var output = [];
var sheetName = sheet.getName();
var header = values[0];
for (var i = 1; i < numRows; i++) {
var row = values[i];
var name = row[0];
var obj = {};
for (var j = 0; j < numCols; j++) {
var key = header[j];
var value = row[j];
obj[key] = value;
}
output.push(obj);
}
Logger.log(output);
var firebaseUrl = "https://webvr-6345b.firebaseio.com/webvrrocks/" + sheetName + "/";
var base = FirebaseApp.getDatabaseByUrl(firebaseUrl);
base.setData("", output);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment