Advertisement
Guest User

Untitled

a guest
May 30th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1.  
  2.  
  3. String.prototype.trimLeft = function(){ return this.replace(/^\s+/,'') }
  4. String.prototype.trimRight = function(){ return this.replace(/\s+$/,'') }
  5. String.prototype.trim = function(){ return this.trimLeft().trimRight() }
  6.  
  7. function readSheet(){
  8.  
  9. var dataFileId = ""; //TODO: add your data.txt file id
  10. var ssFileId = ""; //TODO: add your spreadsheet file id
  11.  
  12. var content = DriveApp.getFileById(dataFileId).getAs('application/json').getDataAsString();
  13. //Logger.log(content);
  14.  
  15. var data = JSON.parse(content);
  16. //Logger.log(data);
  17.  
  18. var ss = SpreadsheetApp.openById(ssFileId);
  19. //SpreadsheetApp.flush();
  20.  
  21. var sheet = ss.getActiveSheet();
  22.  
  23. //Clear content if you open ss in edit mode.
  24. if (sheet.getLastRow() > 1 || sheet.getMaxColumns() > 1 ){
  25. sheet.getRange(1, 1, sheet.getLastRow(), sheet.getMaxColumns()).clear();
  26. }
  27.  
  28. for (var i = 0; i < data.length; i++) {
  29. for (j = 0; j < data[i].length; j++) {
  30. var destinationRange = sheet.getRange(i+1, j+1, 1, 1);
  31. destinationRange.setValue(data[i][j].VALUE.trim());
  32.  
  33. if (data[i][j].NUMBER !== undefined && data[i][j].FORMAT !== undefined) {
  34. destinationRange.setNumberFormat(data[i][j].FORMAT.trim());
  35. }
  36. if (data[i][j].STYLE !== undefined && data[i][j].STYLE.BACKGROUNDCOLOR !== undefined) {
  37. destinationRange.setBackground(data[i][j].STYLE.BACKGROUNDCOLOR.trim());
  38. }
  39. if (data[i][j].STYLE !== undefined && data[i][j].STYLE.COLOR !== undefined) {
  40. destinationRange.setFontColor(data[i][j].STYLE.COLOR.trim());
  41. }
  42. }
  43. }
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement