References

Code

function getSheetByGid(spreadsheet, gid) {
    gid = +gid || 0; // gid가 숫자가 아닌 경우 0
		if(gid === 0) return undefined;

    var sheets_ = spreadsheet.getSheets();
    for(var i = sheets_.length; i--; ) {
        if(sheets_[i].getSheetId() === gid) {
            return sheets_[i];
        }
    }

    return undefined;
}

var sheet = SpreadsheetApp.openById("YOUR_SHEET_ID_HERE");
var seetWithGid = getSheetByGid(cpSheet, "YOUR_GID_HERE");