Last active
March 23, 2020 18:05
-
-
Save cvan/b79ddc1abbe5173aaaddbe241bfc8e54 to your computer and use it in GitHub Desktop.
Google Spreadsheets script for syncing to Firebase
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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://YOUR_APP_NAME.firebaseio.com/YOUR_PROJECT_NAME/" + 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
@pacozevallos
you have to install this library first