Skip to content

Instantly share code, notes, and snippets.

@isummation
Last active September 29, 2016 10:05
Show Gist options
  • Select an option

  • Save isummation/00a72cd90bb231118bd482c3cd086140 to your computer and use it in GitHub Desktop.

Select an option

Save isummation/00a72cd90bb231118bd482c3cd086140 to your computer and use it in GitHub Desktop.
String.prototype.trimLeft = function(){ return this.replace(/^\s+/,'') }
String.prototype.trimRight = function(){ return this.replace(/\s+$/,'') }
String.prototype.trim = function(){ return this.trimLeft().trimRight() }
function readSheet(){
var dataFileId = ""; //TODO: add your data.txt file id
var ssFileId = ""; //TODO: add your spreadsheet file id
var content = DriveApp.getFileById(dataFileId).getAs('application/json').getDataAsString();
//Logger.log(content);
var data = JSON.parse(content);
//Logger.log(data);
var ss = SpreadsheetApp.openById(ssFileId);
//SpreadsheetApp.flush();
var sheet = ss.getActiveSheet();
//Clear content if you open ss in edit mode.
if (sheet.getLastRow() > 1 || sheet.getMaxColumns() > 1 ){
sheet.getRange(1, 1, sheet.getLastRow(), sheet.getMaxColumns()).clear();
}
for (var i = 0; i < data.length; i++) {
for (j = 0; j < data[i].length; j++) {
var destinationRange = sheet.getRange(i+1, j+1, 1, 1);
destinationRange.setValue(data[i][j].VALUE.trim());
if (data[i][j].NUMBER !== undefined &amp;&amp; data[i][j].FORMAT !== undefined) {
destinationRange.setNumberFormat(data[i][j].FORMAT.trim());
}
if (data[i][j].STYLE !== undefined &amp;&amp; data[i][j].STYLE.BACKGROUNDCOLOR !== undefined) {
destinationRange.setBackground(data[i][j].STYLE.BACKGROUNDCOLOR.trim());
}
if (data[i][j].STYLE !== undefined &amp;&amp; data[i][j].STYLE.COLOR !== undefined) {
destinationRange.setFontColor(data[i][j].STYLE.COLOR.trim());
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment