Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 && data[i][j].FORMAT !== undefined) {
- destinationRange.setNumberFormat(data[i][j].FORMAT.trim());
- }
- if (data[i][j].STYLE !== undefined && data[i][j].STYLE.BACKGROUNDCOLOR !== undefined) {
- destinationRange.setBackground(data[i][j].STYLE.BACKGROUNDCOLOR.trim());
- }
- if (data[i][j].STYLE !== undefined && data[i][j].STYLE.COLOR !== undefined) {
- destinationRange.setFontColor(data[i][j].STYLE.COLOR.trim());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement