Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用GAS从侧边栏下载zip文件_Javascript_Google Apps Script_Google Spreadsheet Api - Fatal编程技术网

Javascript 使用GAS从侧边栏下载zip文件

Javascript 使用GAS从侧边栏下载zip文件,javascript,google-apps-script,google-spreadsheet-api,Javascript,Google Apps Script,Google Spreadsheet Api,我想在进程完成时触发文件下载(不使用驱动器服务) 我将编码数据发送回客户机,客户机将编码数据加载到iframe中(因为mime是zip格式的,所以会触发下载) 但是,当数据很大时,我无法下载zip 我试过了 代码.gs //zipBlob = some zipped binary data return { 'contents': "data:application/zip;base64, " + Utilities.base64Encode(zipBl

我想在进程完成时触发文件下载(不使用驱动器服务)

我将编码数据发送回客户机,客户机将编码数据加载到iframe中(因为mime是zip格式的,所以会触发下载)

但是,当数据很大时,我无法下载zip

我试过了

代码.gs

//zipBlob = some zipped binary data
 return {
                    'contents': "data:application/zip;base64, " + Utilities.base64Encode(zipBlob.getAs("application/zip").getBytes())
                };
HTML侧栏

    if (typeof d === 'object') {
       if (d.contents)
            window.open("aboutblank", "Preview").document.write('<head><style>body{margin:0}</style></head><iframe id="iframe" src="' + d.contents + '" scrolling="auto" frameborder="0px" marginheight="0px" marginwidth="0px" height="100%" width="100%"></iframe>');
    }
if(typeof d=='object'){
如果(d.内容)
window.open(“aboutblank”,“Preview”).document.write('body{margin:0}');
}
我找到了答案

 download("export."+d.ext, d.contents)

var download=function(c,b){var a=document.createElement("a"),d=dataURLtoBlob(b);a.setAttribute("href",URL.createObjectURL(d));a.setAttribute("download",c);a.style.display="none";document.body.appendChild(a);a.click();var e;a.addEventListener("click",e=function(){requestAnimationFrame(function(){URL.revokeObjectURL(a.href)});a.removeAttribute("href");a.removeEventListener("click",e)});document.body.removeChild(a)},dataURLtoBlob=function(c){var b=c.split(",");c=b[0].match(/:(.*?);/)[1];if(-1!==b[0].indexOf("base64")){b=
atob(b[1]);for(var a=b.length,d=new Uint8Array(a);a--;)d[a]=b.charCodeAt(a);return new Blob([d],{type:c})}b=decodeURIComponent(b[1]);return new Blob([b],{type:c})};