is it possible to download .csv to my computer using google appscript ?

70 views
Skip to first unread message

Luis Contreras

unread,
Apr 7, 2022, 4:14:12 PM4/7/22
to Google Apps Script Community
Hi team,

I hope are you well.

is it possible to download .csv to my computer using google appscript ? And if it is possible with what command could it be done?

Regards

Bennett, Scott

unread,
Apr 7, 2022, 4:17:02 PM4/7/22
to google-apps-sc...@googlegroups.com
I have a script that does it from an email.

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/2d88314a-fa45-4a22-8b28-bcef5ed7af92n%40googlegroups.com.


--
Scott Bennett
Data and Assessment Coordinator/Math Teacher
Bradley-Bourbonnais Community High School

Luis Contreras

unread,
Apr 8, 2022, 3:21:46 AM4/8/22
to Google Apps Script Community
Hi Scott

Cool! could you share us this code? and we try to change for .csv?

Bennett, Scott

unread,
Apr 8, 2022, 7:18:11 AM4/8/22
to google-apps-sc...@googlegroups.com
function getAttachment() {
  GmailApp.search('fdas',)
  var ss = SpreadsheetApp.getActiveSpreadsheet()
  var sheet = ss.getSheetByName('All Data'); //gets sheet to paste all data from csv
  var lrow = sheet.getLastRow()
  var emails = GmailApp.search('What to search for',0,2)//searches emails for the given string and returns the first 2 that satisfy that search string
  for(i = 0;i<emails.length;i++){//loops through returned messages
    var messages=emails[i].getMessages()
    for(m=0;m<messages.length;m++){//loops through attachments
      var attachment=messages[m].getAttachments()[0
      var csv = Utilities.parseCsv(attachment.getDataAsString())//gets the file as a text file
      csv.shift()//removes headers from file
      Logger.log(csv)
      if(csv.length<800){//if the length is less than 800 rows it copies it to the given sheet.
        sheet.getRange(lrow+1,1,csv.length,csv[0].length).setValues(csv)
      }
    }
  }
}

On Fri, Apr 8, 2022 at 2:21 AM 'Luis Contreras' via Google Apps Script Community <google-apps-sc...@googlegroups.com> wrote:
Hi Scott

Cool! could you share us this code? and we try to change for .csv?

El jueves, 7 de abril de 2022 a las 15:17:02 UTC-5, sben...@bbchs.org escribió:
I have a script that does it from an email.

On Thu, Apr 7, 2022 at 3:14 PM 'Luis Contreras' via Google Apps Script Community <google-apps-sc...@googlegroups.com> wrote:
Hi team,

I hope are you well.

is it possible to download .csv to my computer using google appscript ? And if it is possible with what command could it be done?

Regards

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/2d88314a-fa45-4a22-8b28-bcef5ed7af92n%40googlegroups.com.


--

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.

Bennett, Scott

unread,
Apr 8, 2022, 7:19:35 AM4/8/22
to google-apps-sc...@googlegroups.com
I had to remove that first line.  Here is the corrected version.

function getAttachment() {
  var ss = SpreadsheetApp.getActiveSpreadsheet()
  var sheet = ss.getSheetByName('All Data'); //gets sheet to paste all data from csv
  var lrow = sheet.getLastRow()
  var emails = GmailApp.search('What to search for',0,2)//searches emails for the given string and returns the first 2 that satisfy that search string
  for(i = 0;i<emails.length;i++){//loops through returned messages
    var messages=emails[i].getMessages()
    for(m=0;m<messages.length;m++){//loops through attachments
      var attachment=messages[m].getAttachments()[0
      var csv = Utilities.parseCsv(attachment.getDataAsString())//gets the file as a text file
      csv.shift()//removes headers from file
      Logger.log(csv)
      if(csv.length<800){//if the length is less than 800 rows it copies it to the given sheet.
        sheet.getRange(lrow+1,1,csv.length,csv[0].length).setValues(csv)
      }
    }
  }
}
Reply all
Reply to author
Forward
0 new messages