title: How to export csv from spreadsheett to drive folder
body: <p>I have an spreadsheet with 4 sheets that I need in .CSV format. By now, I have a script that sends me the .csv files to my email, but I need to automacally save it into a google drive folder, do you have any ideas ?</p>
  
  <p>This is my actual script:</p>
  
  <pre class="lang-js prettyprint-override"><code>function Csv(){
  
    var ss = SpreadsheetApp.openById('spreadsheetID');
  
    var url1 = "https://docs.google.com/spreadsheets/d/spreadsheetID/gviz/tq?tqx=out:csv&amp;sheet=Sheet1";
    var url2 = "https://docs.google.com/spreadsheets/d/spreadsheetID/gviz/tq?tqx=out:csv&amp;sheet=Sheet2";
    var url3 = "https://docs.google.com/spreadsheets/d/spreadsheetID/gviz/tq?tqx=out:csv&amp;sheet=Sheet3";
    var url4 = "https://docs.google.com/spreadsheets/d/spreadsheetID/gviz/tq?tqx=out:csv&amp;sheet=Sheet4";
    var params = {
      method      : "get",
      headers     : {"Authorization": "Bearer " + ScriptApp.getOAuthToken()},
      muteHttpExceptions: true
    };
  
    var blob1 = UrlFetchApp.fetch(url1, params).getBlob();
    blob1.setName("File1" +".csv");
    var blob2 = UrlFetchApp.fetch(url2, params).getBlob(); 
    blob2.setName("File2" +".csv");
    var blob3 = UrlFetchApp.fetch(url3, params).getBlob(); 
    blob3.setName("File3" +".csv");
    var blob4 = UrlFetchApp.fetch(url4, params).getBlob(); 
    blob4.setName("File4" +".csv");
  
  
    MailApp.sendEmail("myemail@gmail.com", "Subject", "Body", {attachments: [blob1,blob2,blob3,blob4]});
  
  }
  </code></pre>
  
  <p>Thanks!</p>