【问题标题】:How to Download a file from my Google Drive to my local Downloads file [duplicate]如何将文件从我的 Google Drive 下载到我的本地下载文件 [重复]
【发布时间】:2020-06-24 15:24:17
【问题描述】:

我有一个应用程序脚本,可以将我的一系列电子表格导出到 Google 云端硬盘,但我实际上想从云端硬盘下载此文件。

有人知道我该怎么做吗?

我可以轻松调用 pdf 文件 ID,因为我的脚本结尾是:

var newFile = folder.createFile(theBlob);

  return true;
}

这意味着我可以开始下一个脚本:

var fileToExport = newFile.getId();

请问有人知道解决办法吗?

【问题讨论】:

    标签: google-apps-script google-sheets


    【解决方案1】:

    下载从 Google Sheet 创建的 PDF 文件

    我使用我发现的一些不同的东西来解决这个问题,我使用了我之前在脚本中创建的.getDownloadUrl() 中的theBlob。然后我使用了来自:https://stackoverflow.com/a/47098533/12139658 的一些脚本,它打开了一个新的 url:

      var html = HtmlService.createHtmlOutput('<html><script>'
      +'window.close = function(){window.setTimeout(function(){google.script.host.close()},9)};'
      +'var a = document.createElement("a"); a.href="'+url+'"; a.target="_blank";'
      +'if(document.createEvent){'
      +'  var event=document.createEvent("MouseEvents");'
      +'  if(navigator.userAgent.toLowerCase().indexOf("firefox")>-1){window.document.body.append(a)}'                          
      +'  event.initEvent("click",true,true); a.dispatchEvent(event);'
      +'}else{ a.click() }'
      +'close();'
      +'</script>'
      // Offer URL as clickable link in case above code fails.
      +'<body style="word-break:break-word;font-family:sans-serif;">Failed to open automatically. <a href="'+url+'" target="_blank" onclick="window.close()">Click here to proceed</a>.</body>'
      +'<script>google.script.host.setHeight(40);google.script.host.setWidth(410)</script>'
      +'</html>')
      .setWidth( 90 ).setHeight( 1 );
      SpreadsheetApp.getUi().showModalDialog( html, "Opening ..." );
    

    这真是太棒了。

    【讨论】:

      猜你喜欢
      • 2013-06-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-11
      • 2019-02-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多