Is it possible to publish a Google Spreadsheet to the web using Google Apps Scripts? Right now I have to do it manually using File
> Publish to the web...
.
I checked all of the Google Apps Scripts references and guides but don't see anything about publishing a script through GAS automation.
File
> Publish to the web...
using Google Apps Script.If my understanding is correct, how about this sample script?
When you use this script, please enable Drive API at Advanced Google Services.
var spreadsheetId = "###"; // Please set this.
Drive.Revisions.update({published: true, publishedOutsideDomain: true, publishAuto: true}, spreadsheetId, 1);
- publishAuto: Whether subsequent revisions will be automatically republished. This is only populated and can only be modified for Google Docs.
- published: Whether this revision is published. This is only populated and can only be modified for Google Docs.
- publishedOutsideDomain: Whether this revision is published outside the domain. This is only populated and can only be modified for Google Docs.
1
as the default, when new Spreadsheet is created. And by publishAuto
, when the Spreadsheet is updated, the updated Spreadsheet is automatically reflected to the published Spreadsheet.
If I misunderstood your question and this was not the result you want, I apologize.
About the URL of published Spreadsheet, when the Spreadsheet is published manually, the URL can be retrieved like https://docs.google.com/spreadsheets/d/e/2PACX-###/pubhtml
. In this case, 2PACX-###
is not the Spreadsheet ID. Unfortunately, in the current stage, this URL cannot be retrieved by API. Drive API v2 had retrieved it with publishedLink
before. But now, it cannot be retrieved. When Drive API is updated from v2 to v3, publishedLink
was removed. This is the current situation.
But as a workaround, you can create the URL of published Spreadsheet using Spreadsheet ID. Please check the following URL.
https://docs.google.com/spreadsheet/pub?key=### spreadsheetId ###
You can access the published Spreadsheet using above URL.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.