To link a script to a Google Site, you need to follow the following steps:
- Open your Google Site and navigate to the page where you want to add the link to your script.
- Click on the “Insert” button in the top menu, then select “Link”.
- In the link dialog box, select “Apps Script” from the “Link Type” dropdown menu.
- Select your script from the list of available scripts.
- Choose the function you want to link to.
- Click “OK” to insert the link to your script.
Here’s an example of how to create a new file in Google Sheets using a script linked to a Google Site:
function createNewSheet() {
var ss = SpreadsheetApp.create("New Sheet");
var sheet = ss.getActiveSheet();
sheet.getRange("A1").setValue("Hello World!");
}
Once you’ve linked this script to your Google Site, you can create a link to the createNewSheet
function, and users can click on it to create a new sheet with the text “Hello World!” in cell A1.