javascript - Problems with arrays in Google Apps Script and Google Spreadsheet -


ok, problem there no way set range explictly without information on width , height. if have 13 cells, why wouldn't write 13 cells? so, here script:

function onopen() {   var ss = spreadsheetapp.getactivespreadsheet();   var targetsheet = ss.getsheetbyname("analytics");   var entries = [{     name : "read data",     functionname : "readrows"   }];   ss.addmenu("script center menu", entries);   var rows = targetsheet.getdatarange();   var numrows = rows.getnumrows();   var values = rows.getvalues();   targetsheet.getrange(1,1,values.length,values[0].length).setvalues(values);   values[1] = readrows();   rows.setvalues(values); }; 

readrows() returns array of values. worked appendrow() can't find way override second row in table without complications. tried everything. way keeps complaining incorrect range height. other ways wrote whole array each cell of row. can't how thing works. seems absolutely illogical.

i mean i'm looking setrow(2, readrows()) take many cells there values in array , override have been written there before that, if any.

ok, found answer. looks way:

function onopen() {   var ss = spreadsheetapp.getactivespreadsheet();   var targetsheet = ss.getsheetbyname("analytics");   var array = [];   var data = [];   var entries = [{     name : "read data",     functionname : "readrows"   }];   ss.addmenu("script center menu", entries);   array = readrows();   data[0]=array;   var range = targetsheet.getrange('a2:m2');   range.setvalues(data); }; 

the trick add array array , achieve two-dimensional array — format setvalues() , getvalues() functions work if want modify single line. seems there no simpler option setarray() or that.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -