title: How to create a *.csv text file from the contents of certain columns?
body: <p>I would like to export the contents of the columns C &amp; D (see red marking in the screenshot) as a text file using a button according to the scheme NYSE:GE,NYSE:BAC,... without breaks, spaces, etc.</p>
  
  <p>The selection of the data should also be linked to certain conditions.</p>
  
  <p>Example: Export all contents of columns C &amp; D where the columns A, H, I and U (see blue marking in screenshot) contain something specific.</p>
  
  <p>Ideally, it would be possible to set the conditions in the table using a drop-down selection, then retrieve the conditions in the code and trigger the export accordingly using a button.</p>
  
  <p><strong>Update:</strong> For my case I have changed the code from Cooper to the following. This works for me. Thanks to Cooper :-)</p>
  
  <pre><code>function cAndDtoCSV(filename) {
  
    var filename=filename||'Watchlist.csv';
    var ss=SpreadsheetApp.getActive();
    var sh=ss.getActiveSheet();
    var rg=sh.getDataRange();
    var rg1 =ss.getRange(""); //Get range of conditions
    var vA=rg.getValues();
    var Cd1 = rg1.getCell().getValue(); //Get value of condition No.1
    var Cd2 = rg1.getCell().getValue(); //Get value of condition No.2
    var Cd3 = rg1.getCell().getValue(); //Get value of condition No.3
    var csv="";
    for(var i=0;i&lt;vA.length;i++) {
      if(vA[i][0]==Cd1 &amp;&amp; vA[i][7]==Cd2 &amp;&amp; vA[i][8]==Cd3) {  
        csv+=Utilities.formatString('%s,%s\r\n', vA[i][2],vA[i][3]);
      }
    }
    var file=DriveApp.createFile(filename,csv,MimeType.CSV);
  }
  </code></pre>