This post is going to show your 2 ways in which you can get the spreadsheet ID in Google Sheets.
Using Apps Script
The first way is via Apps Script. You can run the following code on Apps Script to get the spreadsheet ID.
function getActiveSpreadsheetID() {
var spreadSheetId = SpreadsheetApp.getActiveSpreadsheet().getId();
console.log("spreadSheet ID = "+ spreadSheetId);
return spreadSheetId;
}
To run Apps Script, go to Extensions -> Apps Script
Copy and paste the above code into Apps Script. You will need to Save project before you can run the script. When running the script for the first time, it will prompt you to review permission. Follow the steps below to grant permission to the script.
When you run this script, it will return the active spreadsheet ID. As you can see from the console log in this example, the spreadSheet ID is “1ZSXomxm-LzVHdNGHKqcAYgRkBf1TyEMux__Uvqluh1k
“.
Manually via Google Sheets URL
Alternatively, you can also retrieve the Spreadsheet ID from the Google Sheets URL.
https://docs.google.com/spreadsheets/d/SpreadSheetID/edit#gid=0
When you open up a spread sheet in Google Sheets, you should see something similar like this.
In this example, the spreadsheet ID will is “1ZSXomxm-LzVHdNGHKqcAYgRkBf1TyEMux__Uvqluh1k
“