通过Google Apps脚本发布Google电子表格 [英] publish a Google Spreadsheet through Google Apps Scripts

查看:103
本文介绍了通过Google Apps脚本发布Google电子表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用Google Apps脚本在网络上发布Google Spreadsheet?现在,我必须使用File> Publish to the web...手动进行操作.

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

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

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...使用Google Apps脚本.
    • You want to achieve File > Publish to the web... using Google Apps Script.
    • 如果我的理解是正确的,那么该示例脚本如何?

      If my understanding is correct, how about this sample script?

      使用此脚本时,请在高级Google服务中启用Drive API.

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

      官方文件:

      • publishAuto:后续修订是否将自动重新发布.仅填充,并且只能针对Google文档进行修改.
      • 已发布:此版本是否已发布.仅填充该字段,并且只能针对Google文档进行修改.
      • publishedOutsideDomain:此修订是否在域外发布.仅填充,并且只能针对Google文档进行修改.

      注意:

        创建新的电子表格时,
      • 电子表格的修订ID为默认值1.并且通过publishAuto,当电子表格被更新时,更新的电子表格将自动反映到已发布的电子表格中.
        • 我在示例脚本中使用了它们.
        • 如果要修改此设置,请修改脚本.
        • 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.
            • I used them to this sample script.
            • If you want to modify this settings, please modify the script.
              • Advanced Google services
              • Revisions: update

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

              If I misunderstood your question and this was not the result you want, I apologize.

              关于已发布电子表格的URL,当手动发布电子表格时,可以像https://docs.google.com/spreadsheets/d/e/2PACX-###/pubhtml一样检索URL.在这种情况下,2PACX-###不是电子表格ID.不幸的是,在当前阶段,该URL无法通过API检索. Drive API v2之前已使用publishedLink对其进行了检索.但是现在,它无法检索. 将Drive API从v2更新到v3时,publishedLink被删除.这是目前的情况.

              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.

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

              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 ###
              

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

              You can access the published Spreadsheet using above URL.

              这篇关于通过Google Apps脚本发布Google电子表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆