Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Since the CSV format is simple, you can just iterate over the array elements and create the file as String. </p> <p>This is parta of an example code </p> <pre><code> public function exportToCSVStr(data:Array,headersList:Array=null,headerExclude:Array=null):String{ var result:String = ""; for each(var line:String in this.exportToCSV(data,headersList,headerExclude)){ result+=line; } return result; } public function exportToCSV(data:Array,headersList:Array,headerExclude:Array):Array{ if(headerExclude==null)headerExclude=[]; var hedersToExclude:ArrayCollection = new ArrayCollection(headerExclude); var result:ArrayList = new ArrayList(); var headers:String = ""; var hList:ArrayList = new ArrayList(); var i:int=0; if(headersList==null){ for(var h1:String in data[0]){ if(hedersToExclude.contains(h1)) continue; if(i!=0){ headers+=","; } headers+=h1; hList.addItem(h1); i++; } }else{ for each(var h2:* in headersList){ if(i!=0){ headers+=","; } headers+=h2["label"]; hList.addItem(h2["attr"]); i++; } } headers+=newLineDelim; result.addItem(headers); for each(var item:* in data){ var itemStr:String=""; i=0; for each(var attr:String in hList.toArray()){ if(i!=0){ itemStr+=","; } itemStr+=toCSVString(item[attr]); i++; } itemStr+=newLineDelim; result.addItem(itemStr); } return result.toArray(); } protected function toCSVString(data:*):String{ if(data==null) return ""; if(data is Date){ return strDelim + dateFormatter.format(data) + strDelim; } else if(data is String){ return strDelim + data + strDelim; } else if(data is Number) { return numberFormatter.format(data); }else { return data; } } </code></pre> <p>And then you can create the file with</p> <pre><code>var fr:FileReference = new FileReference(); fr.save(csvUtil.exportToCSVStr(alist.toArray(),getCsvIncludeHeaders()),getFileNameTitle()); </code></pre> <p>Davide</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload