简体   繁体   English

通过 Google Apps Scripts 发布 Google 电子表格

[英]publish a Google Spreadsheet through Google Apps Scripts

Is it possible to publish a Google Spreadsheet to the web using Google Apps Scripts?是否可以使用 Google Apps 脚本将 Google 电子表格发布到网络上? Right now I have to do it manually using File > Publish to the web... .现在我必须使用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.我检查了所有 Google Apps 脚本参考和指南,但没有看到任何关于通过 GAS 自动化发布脚本的信息。

  • You want to achieve File > Publish to the web... using Google Apps Script.您想使用 Google Apps 脚本实现File > Publish to the web...

If my understanding is correct, how about this sample script?如果我的理解是正确的,这个示例脚本怎么样?

When you use this script, please enable Drive API at Advanced Google Services.使用此脚本时,请在高级 Google 服务中启用 Drive API。

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. publishAuto:是否会自动重新发布后续修订版。 This is only populated and can only be modified for Google Docs.这仅被填充并且只能针对 Google Docs 进行修改。
  • published: Whether this revision is published.已发布:此修订版是否已发布。 This is only populated and can only be modified for Google Docs.这仅被填充并且只能针对 Google Docs 进行修改。
  • publishedOutsideDomain: Whether this revision is published outside the domain. publishOutsideDomain:此修订版是否在域外发布。 This is only populated and can only be modified for Google Docs.这仅被填充并且只能针对 Google Docs 进行修改。

Note:笔记:

  • Spreadsheet has the revision ID of 1 as the default, when new Spreadsheet is created.创建新电子表格时,电子表格的修订 ID 为1作为默认值。 And by publishAuto , when the Spreadsheet is updated, the updated Spreadsheet is automatically reflected to the published Spreadsheet.并且通过publishAuto ,当电子表格更新时,更新的电子表格会自动反映到已发布的电子表格中。
    • 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 .关于已发布电子表格的网址,手动发布电子表格时,可以像https://docs.google.com/spreadsheets/d/e/2PACX-###/pubhtml那样检索https://docs.google.com/spreadsheets/d/e/2PACX-###/pubhtml In this case, 2PACX-### is not the Spreadsheet ID.在这种情况下, 2PACX-###不是电子表格 ID。 Unfortunately, in the current stage, this URL cannot be retrieved by API.不幸的是,在当前阶段,API 无法检索到此 URL。 Drive API v2 had retrieved it with publishedLink before. Drive API v2 之前已经使用publishedLink检索过它。 But now, it cannot be retrieved.但现在,它无法恢复。 When Drive API is updated from v2 to v3, publishedLink was removed.当 Drive API 从 v2 更新到 v3 时, publishedLink被删除。 This is the current situation.这就是目前的情况。

But as a workaround, you can create the URL of published Spreadsheet using Spreadsheet ID.但作为一种解决方法,您可以使用电子表格 ID 创建已发布电子表格的 URL。 Please check the following URL.请检查以下网址。

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

You can access the published Spreadsheet using above URL.您可以使用上述 URL 访问已发布的电子表格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM