javascript - Google Sheets Script Error - Cannot convert Array to Object[][] -


i'm working on script encode data in fields insertion html (the cells contain words planétarium , rua joão bettega, 01). getting error , don't know it. error says "cannot convert array object[][]"

i'm passing two-dim array .setvalues(), know that's not (found common problem). ideas? here's function:

// columns[] , columns2encode[] set in scope above function function _encodedata() {   var sheet = _getsheet();   var data = sheet.getdatarange().getvalues();   var rowcnt = data.length;   var colcnt = data[0].length;   var data2set = new array(rowcnt-1); // creates array w/ row.length indeces   var colencodeindexlist = [];   var origval, encodedval, range, cell; // used later in loop(s)    toast('start encoding data');    // loop every row   for(var ri = 0; ri < data.length; ri++) {     if(ri !== 0) {       data2set[ri] = new array(colcnt); // creates array w/ length of ~ 29     }      // loop every cell (column entry in given row)     for(var ci = 0; ci < data[ri].length; ci++) {       // text content of current cell       origval = data[ri][ci];        // if first row, headers - save matches in array later       if(ri === 0) { // split ifs inarray isn't called every time         if(inarray(columns2encode, origval)) { // add col header if "on list"           colencodeindexlist.push(ci);         }       } else { // isn't header row         // if ! first row, values - col num must in saved headers encode or it's number         if(!inarray(colencodeindexlist, ci) || typeof origval === 'number') {           // use origval           data2set[ri][ci] = origval;         } else {           // use encodedval           encodedval = _htmlencode(origval);            data2set[ri][ci] = encodedval;         }       } // else     } // (cells/cols)   } // (rows)    // pass array of arrays (data) setvalues()   var setrange = sheet.getrange(2, 1, (data.length-1), data[0].length);//.geta1notation(); // starts @ 2, 1 (row 2, col 1) ignore column header   setrange.setvalues(data2set);    toast('finished encoding data'); } 

thanks in advance!

the problem data2set[0] never initialized (it null).

the easiest way fix problem remove data2set[0] before outputting spreadsheet:

  data2set.shift(); // remove 1st item   setrange.setvalues(data2set); 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -