arrays - Moving rows from spreadsheets to new documents based on owner name with filling information in document -


i have spreadsheet named project log have 6 columns,

timestamp   task    owner   date    keywords    email 

here have different owners. need create document owner name , move particular owner row owner document.

i able looping had issue when duplicate names creating document , sending data per requirement need have 1 document on particular owner , move duplicate owner name owner itself.

example of owner column.

  joe   john   john 

here need create document "joe" name , append body whole row have 2 "john"s need create 1 document i.e., "john" , move 2 rows single document if find more on name should able send row particular owner document.

and looping code is:

function createdocfromsheet() {     var ss = spreadsheetapp.getactivespreadsheet();     var sheet =  ss.setactivesheet(ss.getsheets()[2]);     var numrows=ss.getlastrow();     var values = ss.getdatarange().getvalues()      for(n=2;n<=values.length;++n) {         var cell = sheet.getrange(n,3).getvalue();         var row = sheet.getrange(n,2,1,5).getvalues();         var newdoc = documentapp.create("task report - "+cell);         var body = newdoc.getbody();         body.insertparagraph(0,row);          newdoc.saveandclose();      } } 

if name repeating in column once, can firstindex , lastindex of range array , check if 2 positions matches or not.

giving algorithmic code below:

var array1 = sheet.getrange(1,3,sheets.getlastrow()).getvalues(); (example values might array1 = [a,b,c,a,c,d]) var var1 =  sheet.getrange(n,3).getvalue(); var var2 = array1.indexof(var1); var var3 = array1.lastindexof(var1);   if(var2 == var3) { // means there no repetition of name. } else{ //get values both rows , create document. // make flag variable array note doc created name. } 

hope helps!


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -