javascript - Add dummy parameter to Custom function for Google sheets -
i have custom function below; moves columns 1 sheet different sheet in google sheets
i got here non-contiguous column copy 1 spreadsheet in google apps
i need add dummy
parameter can refresh data pulls
i tried doing this: function copycolumns(sourcerange,start,sheetkey, dummy)
(which has worked other custom functions)
but keep getting error:
problem getting sheet1 - exception: not have permission perform action. (line 31).
which is: throw "problem getting sheet" + sheetkey + " - " + err;
i know vba
new google script writing, have tried have not worked out how this
thanks
/* =copycolumns("mydatasheet!c,a,w",8) */ function copycolumns(sourcerange,start,sheetkey) { // initialize optional parameter if(!sheetkey && typeof start!== "number") { sheetkey = start; start = 1; } else { start = start || 1; } // check sourcerange input var inputre = /^((.*?!)(?=[a-z],?|[a-i][a-z]))?[a-i]?[a-z](,[a-i]?[a-z])*$/i; if(!inputre.test(sourcerange)) throw "invalid sourcerange: " + sourcerange; // check start row if(typeof start !== "number") throw "starting row must number! got: " + start; if(start % 1 !== 0) throw "starting row must integer! got: " + start; if(start < 1) throw "starting row can't less 1! got: " + start; // source sheet try { var ss = sheetkey ? spreadsheetapp.openbyid(sheetkey) : spreadsheetapp.getactivespreadsheet(); } catch(err) { throw "problem getting sheet" + sheetkey + " - " + err; } var sheetname = sourcerange.match(/^.*?(?=!)/); var sheet = sheetname ? ss.getsheetbyname(sheetname[0]) : ss.getactivesheet(); // check still valid if(!sheet) throw "could not find sheet name: " + sheetname; if(start > sheet.getlastrow()) throw "no data beyond row: " + start + " last row: " + sheet.getlastrow(); // values var lastcol = sheet.getlastcolumn(); var lastrow = sheet.getlastrow()-start+1; var values = sheet.getrange(start,1,lastrow,lastcol).getvalues(); // desired columns string var desiredcolmatch = sourcerange.match(/([a-i]?[a-z](,[a-i]?[a-z])*)$/i); var desiredcolumns = desiredcolmatch[0].touppercase().split(","); // in case column trying grab doesn't exist in sheet var lastcolid = sheet.getmaxcolumns() - 1; // array 0 indexed, sheet 1 // numerical values of passed in column ids var columns = desiredcolumns.map(function(colid){ var num = colid.length - 1; // 0 or 1 var colnum = colid.charcodeat(num)-65+num*26*(colid.charcodeat(0)-64); if(colnum > lastcolid) throw "invalid column: " + colid + " - column not in: " + sheetname; return colnum; }); //map values new array of columns want return values.map(function(row){ return columns.map(function(col){ return row[col] }) }); }
the error isn't related use of dummy parameter. error occurs because custom functions can't call services requires authorization run. specifically, spreadsheet service (spreadsheetapp) requires authorization ran.
from https://developers.google.com/apps-script/guides/sheets/functions#using_apps_script_services
unlike other types of apps scripts, custom functions never ask users authorize access personal data. consequently, can call services not have access personal data, ...
Comments
Post a Comment