How to download created csv file using Google Apps Script?

前端 未结 3 805
天涯浪人
天涯浪人 2021-01-13 00:29

I\'ve created a file in Google Apps Script as follows

DocsList.createFile(
   \"test.csv\", 
   \"Row1Col1,Row1Col2 \\r\\n Row2Col1,RowCol2 \\r\\n Row3Col1,R         


        
3条回答
  •  日久生厌
    2021-01-13 00:51

    To download a file with apps script you need to either publish the app, and use the doGet() method (otherwise the "downloadFileAs" won't work)

    OR...

    create the file in Drive, and provide a link in a dialog ui. here are two options for links, one requires users to be logged in the other doesn't taken from here

      var dat=getFileDataFromAnotherFunction();
      var file = DriveApp.createFile('name.csv',dat);
      var t = HtmlService.createTemplateFromFile('DownloadDialog');
      t.url1 = getDlUrl(file);
      t.url2 = file.getDownloadUrl().replace('&gd=true','') 
      rt =  t.evaluate().setSandboxMode(HtmlService.SandboxMode.IFRAME);
      uia.showModalDialog(rt,'Download the csv')
    

    where "DownloadDialog.html"

    is the following file (also in the script editor )

    
    

提交回复
热议问题