I only know the name of that file (it is a Google sheet file) and not the file id. Not possible to get file id manually. Also, there is only one file with this name in my drive. The name is a "abc". So, no iterations required to find this file. The file is not open.
I want to set the value of cell D1 in this file to file name, which is "abc".
I am a beginner and I would need entire code. Please help.
My status:
//get sheet id
var sheetid = DriveApp.getFilesByName('abc').next().getId();
//change cell d1
SpreadsheetApp.openById(sheetid).getSheetByName('abc').getRange('D1').setValue('abc');
}
Result = Error = TypeError: Cannot read property 'getRange' of null
CodePudding user response:
Your .getRange() is null most likely because your .getSheetByName('abc') is incorrect.
- If you know there is only one sheet within this file you can remove .getSheetByName('abc') and it will work.
- If you know the sheet name within the file, replace 'abc' with that name.
https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet#getSheetByName(String)