繁体   English   中英

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

[英]Publish a Google Spreadsheet through Google Apps Scripts #2

我正在尝试通过脚本代码发布一个网络应用程序。 我读了这篇文章,但我无法让它工作,也许情况略有不同。 我有一个复制电子表格的脚本:在脚本中,我想将电子表格的新副本发布为网络应用程序,如果可能,检索其公共 URL(任何人都应该能够访问它)。

这是我的代码:

  // Make a copy of the spreadsheet
  var repliesFile = responseTemplate.makeCopy('risposte', newFolder);
  var repliesId = SpreadsheetApp.openById(repliesFile.getId());

  // pubblish the new copy as a web app
  Drive.Revisions.update({published: true, publishedOutsideDomain: true, publishAuto: true}, repliesId, 1);

  // of course, this doesn't work.. I need a way to get the web app public url of the new copy
  var webAppUrl = ScriptApp.getService().getUrl(); 

我收到 404 错误。 我究竟做错了什么? Drive Api v.2 在脚本中启用。 感谢你给与我的帮助!

  • 您要发布复制的电子表格。
  • 您想要检索已发布电子表格的 URL。
  • 您想通过修改脚本来实现这一点。

如果我的理解是正确的,这个答案怎么样? 请将此视为几种可能的答案之一。

改装要点:

  • 在您的脚本中,我认为repliesId不正确。 它是电子表格对象。 请使用repliesFile.getId()作为文件 ID。
  • 不幸的是,在当前阶段,无法检索到像https://docs.google.com/spreadsheets/d/e/2PACX-###/pubhtml这样的 URL。 但是您可以将https://docs.google.com/spreadsheet/pub?key=### spreadsheetId ###作为已发布电子表格的 URL。

修改后的脚本:

当您的脚本被修改时,请进行如下修改。

从:
 Drive.Revisions.update({published: true, publishedOutsideDomain: true, publishAuto: true}, repliesId, 1);
到:
 var fileId = repliesFile.getId(); Drive.Revisions.update({published: true, publishedOutsideDomain: true, publishAuto: true}, fileId, 1); var url = "https://docs.google.com/spreadsheet/pub?key=" + fileId;
  • url可用作已发布电子表格的 URL。

笔记:

  • 在这种情况下,请在高级 Google 服务中启用 Drive API。

参考:

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

暂无
暂无

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

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