gpt4 book ai didi

google-apps-script - 通过 Google Apps 脚本发布 Google 电子表格

转载 作者:行者123 更新时间:2023-12-03 15:02:45 25 4
gpt4 key购买 nike

是否可以使用 Google Apps 脚本将 Google 电子表格发布到网络上?现在我必须使用 File > Publish to the web... 手动完成。

我检查了所有 Google Apps 脚本引用和指南,但没有看到任何关于通过 GAS 自动化发布脚本的信息。

最佳答案

  • 您想使用 Google Apps 脚本实现 File > Publish to the web...

如果我的理解是正确的,这个示例脚本怎么样?

当您使用此脚本时,请在 Advanced Google Services 中启用 Drive API。

示例脚本:

var spreadsheetId = "###"; // Please set this.
Drive.Revisions.update({published: true, publishedOutsideDomain: true, publishAuto: true}, spreadsheetId, 1);

Official document:

  • 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.

备注:

  • 创建新电子表格时,电子表格的修订 ID 默认为 1。并且通过 publishAuto,当 Spreadsheet 更新时,更新的 Spreadsheet 会自动反射(reflect)到发布的 Spreadsheet 中。
    • 我将它们用于此示例脚本。
    • 如果要修改此设置,请修改脚本。

引用资料:

如果我误解了您的问题并且这不是您想要的结果,我深表歉意。

编辑:

关于发布的电子表格的URL,当手动发布电子表格时,可以像https://docs.google.com/spreadsheets/d/e/2PACX-###/pubhtml。在这种情况下,2PACX-### 不是电子表格 ID。不幸的是,在当前阶段,API 无法检索此 URL。 Drive API v2 之前使用 publishedLink 检索过它。可现在,却再也找不回来了。 When Drive API is updated from v2 to v3, publishedLink was removed.这是目前的情况。

但作为解决方法,您可以使用电子表格 ID 创建已发布电子表格的 URL。请检查以下 URL。

    https://docs.google.com/spreadsheet/pub?key=### spreadsheetId ###

您可以使用上述 URL 访问已发布的电子表格。

关于google-apps-script - 通过 Google Apps 脚本发布 Google 电子表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13016395/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com