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

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

问题描述

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

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

解决方案

  • 你要实现文件 >发布到网络... 使用 Google Apps 脚本.

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

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

示例脚本:

var spreadsheetId = "###";//请设置这个.Drive.Revisions.update({published: true, publishedOutsideDomain: true, publishAuto: true}, spreadsheetId, 1);

<块引用>

官方文档:

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

注意:

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

参考资料:

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

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

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

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

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

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.

解决方案

  • You want to achieve 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.

Sample script:

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.

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.

References:

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

Edit:

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.

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

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