是否可以使用 Google Apps 脚本将 Google 电子表格发布到网络上?现在我必须使用手动执行此操作File
> Publish to the web...
.
我检查了所有 Google Apps 脚本参考和指南,但没有看到任何有关通过 GAS 自动化发布脚本的内容。
- 你想要实现
File
> Publish to the web...
使用 Google Apps 脚本。
如果我的理解是正确的,那么这个示例脚本怎么样?
当您使用此脚本时,请在高级 Google 服务中启用 Drive API。
示例脚本:
var spreadsheetId = "###"; // Please set this.
Drive.Revisions.update({published: true, publishedOutsideDomain: true, publishAuto: true}, spreadsheetId, 1);
官方文件: https://developers.google.com/drive/api/v2/reference/revisions/update
- publishAuto:后续修订是否会自动重新发布。这只是填充的,并且只能针对 Google 文档进行修改。
- 已发布:此修订是否已发布。这只是填充的,并且只能针对 Google 文档进行修改。
- publishedOutsideDomain:此修订版本是否在域外发布。这只是填充的,并且只能针对 Google 文档进行修改。
Note:
- Spreadsheet has the revision ID of
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.
- 我将它们用于此示例脚本。
- 如果要修改此设置,请修改脚本。
参考:
- 高级谷歌服务 https://developers.google.com/apps-script/guides/services/advanced
- 修订内容:更新 https://developers.google.com/drive/api/v2/reference/revisions/update
如果我误解了你的问题并且这不是你想要的结果,我深表歉意。
Edit:
关于发布电子表格的URL,当手动发布电子表格时,可以像这样检索URLhttps://docs.google.com/spreadsheets/d/e/2PACX-###/pubhtml
。在这种情况下,2PACX-###
不是电子表格 ID。不幸的是,在现阶段,API 无法检索该 URL。 Drive API v2 已通过以下方式检索它publishedLink
前。但现在,已经无法找回了。当 Drive API 从 v2 更新到 v3 时,publishedLink去掉了。 https://developers.google.com/drive/v3/web/migration这就是目前的情况。
但作为解决方法,您可以使用电子表格 ID 创建已发布电子表格的 URL。请检查以下网址。
https://docs.google.com/spreadsheet/pub?key=### spreadsheetId ###
您可以使用上面的 URL 访问已发布的电子表格。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)