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:
- i have specify folder id in , don't want to. want code run in current directory (and make recursive scan subfolders well).
- the file class doesn't have "getsheetbyname()" or "getrange()" methods, don't know how cast files spreadsheets.
any appreciated.
cheers
where launching script from? no way of launching script directly google drive.
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
Post a Comment