简体   繁体   English

Google表格Web应用程序下载作为文件停止工作

[英]Google Sheets Web App downloadAsFile Stopped Working

We have a series of Google Sheets which contain data for our application, and we have written scripts behind each one to output that data in json format (as a download) which we then use. 我们有一系列Google表格,其中包含我们应用程序的数据,我们在每个表格后面编写了脚本,以json格式(作为下载)输出我们随后使用的数据。 This is done by publishing each script as a web app, and then linking to the URL from an HTML dialog. 这是通过将每个脚本发布为Web应用程序,然后从HTML对话框链接到URL来完成的。 The web apps looks something like this: Web应用程序看起来像这样:

function doGet()
{
    var exportJSON = getExportJSON();
    var output = ContentService.createTextOutput(exportJSON);
    output.downloadAsFile("filename.json");
    return output;
}

function getExportJSON()
{
    var exportArray = [];
    fillInExportArray(exportArray);
    return JSON.stringify(exportArray, null, 4);
}

This has worked very well for a while, but on Wednesday (5th April 2017) it suddenly stopped working. 这已经有一段时间了,但是在星期三(2017年4月5日),它突然停止了工作。 What happens now is that the download dialog comes up, but where it used to put the filename (filename.json in my example) it now has the word "echo" (without the quotes). 现在发生的是下载对话框出现了,但是它用来放置文件名(在我的例子中是filename.json)它现在有“echo”(没有引号)这个词。 If I choose a location to download the file, and click ok the download appears in my download bar in Chrome, but it says "Failed - Network error" underneath it. 如果我选择下载文件的位置,然后点击“确定”,Chrome下载栏中会显示下载,但下方会显示“失败 - 网络错误”。

As I said we have a number of sheets which use the same pattern, but they are completely separate scripts and web apps. 正如我所说,我们有许多使用相同模式的工作表,但它们是完全独立的脚本和Web应用程序。 This problem appeared on all the sheets at the some time, without them being changed, so I'm assuming it's not something we've done. 这个问题在一段时间内出现在所有纸张上,没有更改,所以我假设这不是我们已经完成的事情。

update: I forgot to say that if I go into the script editor, and select Publish -> Deploy as web app, and then click the "latest code" link the download works fine. 更新:我忘了说,如果我进入脚本编辑器,并选择发布 - >部署为Web应用程序,然后单击“最新代码”链接下载工作正常。

update 2: I've just realised that this problem is happening for some of us in the office, but not others. 更新2:我刚刚意识到办公室里的一些人正在发生这个问题,而其他人则没有。

The problem is that as I was activating the link to the webapp from an HTML modal dialog from the Google Sheet, and that was causing this error to appear: 问题是,当我从Google Sheet中的HTML模式对话框激活webapp的链接时,导致出现此错误:

Refused to display 'https://...' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'. 拒绝在框架中显示“https:// ...”,因为它将“X-Frame-Options”设置为“SAMEORIGIN”。

So I tried the fix as detailed in this thread: App Script HTMLService App in iFrame , but that didn't work, so in the end I just added target="_blank" to the link HTML and it opens in a new window and works fine. 所以我尝试了这个帖子中详细介绍的修复程序: iFrame中的App脚本HTMLService应用程序 ,但是没有用,所以最后我只是将链接HTML中的target="_blank"到新窗口并打开精细。

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

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