How do I export my Datagrid results to a CSV or MS Excel File using Flex?

Hey there,

I've spent several hours trying to understand how to simply take my Datagrid values and save them to a CSV. After lots of searching around, I found the following article the PARTIALLY does what I'm looking for:

http://www.abdulqabiz.com/blog/archives/2007/08/03/datagriddataexporter-export-datagrid-data-as-csv/

The problem with his code is that it just spits out the CSV. I want to literally have a file save as dialog box so the user can save the CSV file to their computer. By the way, his results are not even comma separated.

After reading various methods, I 'now' realize I need something called a Java Servlet, and I have no idea what that is, let alone try to figure out what I need to do.

Can someone please provide me with a downloaded sample FLEX Application that populates information to a datagrid and if I click "Save Results" or something, a dialog box comes up so that I can save the information to my computer? That's all I'm looking for.

I don't understand why I need to do any server side scripting. I don't know PHP, Java, or Java Servlet creating...I'm a new (about 5 days old) developer and trying to learn 'by example'.

If I need to use PHP, Java, or anything of the sort, can you please provide a really detailed explanation trying to step-by-step layout what I need to do? Thanks so much.
piyushdabombAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

piyushdabombAuthor Commented:
oh and by the way, I found something that I'm trying to do here:

http://blog.kukiel.net/2009/01/flex-datagrids-and-excel-part-2.html

problem is that if I view the code and bring it into my Flex, try running it, I get the following error message:

Severity and Description      Path      Resource      Location      Creation Time      Id
'CF_FLEX_OUTPUT_FOLDER\DataGridCopy\' is not a valid location. The location is relative to undefined workspace path variable 'CF_FLEX_OUTPUT_FOLDER'.            DataGridCopy      Unknown      1269381698391      818

I'm so lost :(
0
vindys80Commented:
Hi,

Ya that source is giving "" separated list.
For saving you can use FileReference save function.
http://www.bagonca.com/blog/2009/04/06/triggering-a-save-file-dialogue-from-flex/

But for this you can set your application property as Require Flash player version 10.0.0.

Thanks,
Vindys
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
piyushdabombAuthor Commented:
Vindy,

Thanks for this, but a few things that doesn't help me solve my problem:

From my original post, I specifically mentioned I need to save my results from a DataGrid. How can I take my results from my datagrid to a 'file' which will then get saved? The function above assumes you have a file sitting somewhere already. For example, the example link assumes you have 'Hello.jpg' sitting in the same folder as your main mxml file. My results need to be exported right out of the datagrid.
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

vindys80Commented:
Hi,

I just checked code by Abdul. Its supporting any delimiter for exporting. So you might be able to send ',' as separator and get csv. Save of FileReference can be called from the same function. Only condition would be that it  has to be called from a function which is a userinteraction event like a mouse click on button. Try this code.

Thanks,
Vindys
private function exportCSV ():void
{
	console.text = DataGridDataExporter.exportCSV (dg,',');
	var fileReference:FileReference = new FileReference();
	fileReference.save(DataGridDataExporter.exportCSV (dg,','),myCSV.csv);
}

Open in new window

0
piyushdabombAuthor Commented:
Hey Vindy,

Can I request you to send me a working version of this?

I tried downloading the code from here:
http://www.everythingflex.com/flex3_fp10/savetodisk/srcview/index.html

and I get the following error when I try running the file:

Unknown Flex SDK: "Flex 3.2.0.3266"            SaveToDisk      Unknown      1269563060787      1500

I also tried your function, and I can't seem to get it to work. Where do I place this? If you can either give me a step by step instruction guide or give me the Flex project to make this work, you are the man!
0
piyushdabombAuthor Commented:
Okay Vindy, I'm closer to what I was. But can you help me create a function that takes the results of a datagrid into a single CSV string format? I can then feed it into the following:

private function ExporttoCSV():void{
                        
                        var test:String = "Hello World, By World"
                        file.save(test,'Report.txt');
                  }

It'll then work!
0
vindys80Commented:
Hi,

If you use Abdul's code and change exportCSV() with the function I provided, it will give you the result. Only thing is that you getting error that save is not a function on FileReference. So here is the trouble.

1) FileReference.save() is only there in latest flex sdk. Right now you using sdk 3.2 I think which is bit old. Get new flex sdk.
2) Set required version of flash player as 10.0.0
http://blog.everythingflex.com/2008/05/20/using-flash-player-10-within-flex-builder/

Thanks,
Vindys
0
vindys80Commented:
Hi,

"can you help me create a function that takes the results of a datagrid into a single CSV string format? "

var test:String = DataGridDataExporter.exportCSV (dg,',');

this will give you with , separated text.

If you need next line character as '\r\n', use like this.

var test:String = DataGridDataExporter.exportCSV (dg,',','\r\n');

Thanks,
Vindys
0
piyushdabombAuthor Commented:
Perfect.

Just what I needed. Although the user needs to download Adobe Flash Player 10, who cares! The world needs to be revolving to better quality products.

What's nice about this solution is that there is no server side BS :).
0
vindys80Commented:
Thanks for accepting. Happy to hear that it helped
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.