Created
October 24, 2012 21:17
-
-
Save simenbrekken/3948950 to your computer and use it in GitHub Desktop.
Export Google Spreadsheet as JSON
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 exportJSON() { | |
var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets(); | |
var result = sheets.reduce(function(result, sheet) { | |
var id = sheet.getName().toLowerCase(); | |
var data = sheet.getDataRange(); | |
var values = data.getValues(); | |
result[id] = values.map(function(row) { | |
return row.map(function(column) { | |
return Math.round(column) || column; | |
}).filter(Boolean); | |
}).filter(function(row) { | |
return !!row[0]; | |
}); | |
return result; | |
}, {}); | |
var app = UiApp.createApplication().setTitle('Exported JSON'); | |
var textArea = app.createTextArea().setWidth('100%').setHeight('400px').setText(JSON.stringify(result)); | |
app.add(textArea); | |
SpreadsheetApp.getActiveSpreadsheet().show(app); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment