Explanation:
As you have also noticed, there is no such a method to get a sheet object by its id.
However, you can do some JavaScript
tricks:
Solution:
function myFunction(){
const ss = SpreadsheetApp.getActive();
const sheets = ss.getSheets();
const gid = "1063355045"; // select the gid of your choice
const sheet = sheets.filter(sh=>sh.getSheetId()==gid)[0]; // this is the sheet object
console.log(sheet.getSheetName());
}
sheet
is the desired sheet with the particular gid
. You can apply all the sheet methods to that object.
Construct your own getSheetByGid
function:
function myFunction(){
const gid = "1063355045";
const sheet = getSheetByGid(gid);
}
function getSheetByGid(gid){
const ss = SpreadsheetApp.getActive();
const sheets = ss.getSheets();
const sheet = sheets.filter(sh=>sh.getSheetId()==gid)[0]; // this is the sheet object
return sheet;
}