Report: Publishing Various Google Docs with Same URL using Google Apps Script

Gists

This is a sample method for publishing various Google Docs files with the same URL using Google Apps Script.

By updating on May 25, 2022, the content got to be able to be embedded as a full page in the new Google site. Ref In this method, this is used.

Report: Publishing Various Google Docs with Same URL using Google Apps Script

Usage

1. Create a Google Docs.

First, as a simple sample, please create a new Google Spreadsheet. And please copy the URL like https://docs.google.com/spreadsheets/d/{spreadsheetId}/edit.

2. Create a Google Apps Script project.

You can use both the standalone script type and the container-bound script type.

3. Sample script

Please copy and paste the following script to the script editor of the created Google Apps Script project. And, please set the Google Spreadsheet URL to googleDocs.

function doGet() {
  const googleDocs =
    "https://docs.google.com/spreadsheets/d/{spreadsheetId}/edit";

  const html = `<iframe src="${googleDocs}" style="border: none; width: 95vw; height: 95vh; padding: 0; margin: 0;"></iframe>`;
  return HtmlService.createHtmlOutput(html);
}

4. Deploy Web Apps.

The detailed information can be seen at the official document. In this case, it supposes that you are using new IDE. Please be careful this.

  1. On the script editor, at the top right of the script editor, please click “click Deploy” -> “New deployment”.
  2. Please click “Select type” -> “Web App”.
  3. Please input the information about the Web App in the fields under “Deployment configuration”.
  4. Please select “Me” for “Execute as”.
  5. Please select “Anyone” for “Who has access”.
    • For testing this script, I thought that this setting might be suitable.
  6. Please click “Deploy” button.
  7. Copy the URL of the Web App. It’s like https://script.google.com/macros/s/###/exec.

5. Create a new Google site

Pleases create a new Google site. And, please set the top page as the full page for embeding the content. Ref and Ref I thought that the animation gif might be useful for understanding how to set it.

And, please set your Web Apps URL as the full page content to the created Google site. And, please publish the Google site.

6. Testing

When the above setting is done and you access your published Google site, you can see the situation of the top image in this post on your browser.

Note

Reference

 Share!