Reputation: 109
I want to export the data kept in an actionscript array as a text/CSV file. I have searched and found a few that did datagrid to excel exports but they are complicated and confusing. I understand I have to create a script to handle this and I am wondering if there are examples of doing this?
I need help with: -calling the script within actionscript code (I am not too experienced with this, can it just be something like arrayToCVS(array) ?) -getting the "download" prompt to show up and allowing the user to save the CSV
thanks!
Upvotes: 1
Views: 1465
Reputation: 4238
Something like this should help you. basically it takes an array, creates a number of header columns, and exports all data in the array:
private function exportDataGrid(arr:Array):void{
var exportStr:String = "";
var delimiter:String = ",";
var fileName:String;
fileName = "export.txt";
exportStr += "Title" + delimiter;
exportStr += "Date Created" + delimiter;
exportStr += "Cards" + delimiter;
exportStr += delimiter+delimiter+delimiter+"\n";
for each(var item:Object in arr){
exportStr += "\""+item.title+"\""+delimiter;
exportStr += "\""+item.dateCreated+"\""+delimiter;
exportStr += "\""+item.numCards+"\"\n";
}
var fileReference:FileReference = new FileReference();
fileReference.save(exportStr, fileName);
}
Upvotes: 2