1

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!

1 Answer 1

2

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);
        }
Sign up to request clarification or add additional context in comments.

1 Comment

Wow, thanks so much! I did not know aboutFileReference. It makes things a lot simpler :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.