Miscellaneous‎ > ‎

Get spreadsheet key of the embedded spreadsheet

Do you want to get the spreadsheet key of the spreadsheet which is embedded in current site page :) Here is a quick example which works like a charm.
This question was asked in Google Apps Script Forum. Check this thread for detail (Google Site - spreadsheet embeded - Get the key ?).

Example code:
function doGet() {
//get the active page
var page = SitesApp.getActivePage();
// Get the content of the current page
var htmlContent = page.getHtmlContent();
var filteredContentArray = htmlContent.match(/src=\'http:\/\/spreadsheets.google.com\/spreadsheet\/loadredirect\?chrome=false&key=[0-9A-Za-z]+/g);
var ssKeys = []
for(var i in filteredContentArray){
var key = filteredContentArray[i].match(/key=[A-Za-z0-9]+/)[0].substring(4);
//Create an application to display the spreadsheet keys which are embedded in this page
var app = UiApp.createApplication();
for(var i in ssKeys){
return app;

Sample Embedded Spreadsheets:

Embedded Spreadsheet 1

Embedded Spreadsheet 2

Key of the embedded spreadsheets displayed by Apps Script Gadget: Demo