google apps script - Searching current folder for spreadsheets and changing value in specific cell of each file found -


new google apps script here, have coding experience. want scan current folder spreadsheets. each spreadsheet found, want change value in specific cell (say cell f16 in "sheet1") "q1 fy16". here have far:

function myfunction() {  var folderid ="0bxfgszimm3d9flpvlwxd4bjq"; var topfolder = driveapp.getfolderbyid(folderid); logger.log(topfolder.getname()); var fileslist = topfolder.getfiles();  while (fileslist.hasnext()) {     var file = fileslist.next();     logger.log(file.getname());     file.getsheetbyname("sheet1").getrange("f16").setvalue("q1 fy16");  } } 

there 2 main problems:

  1. i have specify folder id in , don't want to. want code run in current directory (and make recursive scan subfolders well).
  2. the file class doesn't have "getsheetbyname()" or "getrange()" methods, don't know how cast files spreadsheets.

any appreciated.

cheers

  1. where launching script from? no way of launching script directly google drive.

  2. to able use getsheetbyname() , getrange() need open file spreadsheet. instead of using line:

    file.getsheetbyname("sheet1").getrange("f16").setvalue("q1 fy16"); 

you should use :

try { spreadsheetapp.openbyid(file.getid()).getsheetbyname("sheet1").getrange("f16").setvalue("q1 fy16"); }  catch(e){} 

you need use try - catch since of files won't spreadsheet , give , error when trying use spreadsheetapp.openbyid().

i hope helps bit, i'll try update answer once more information first part.

best of luck.


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -