[英]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 在脚本中启用。 感谢你给与我的帮助!
如果我的理解是正确的,这个答案怎么样? 请将此视为几种可能的答案之一。
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。如果我误解了您的问题并且这不是您想要的结果,我深表歉意。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.