I want to use a button in flex to call the function. what would I call? Also, do you know of a coldfusion solution?
Main Topics
Browse All TopicsWhat is the simpliest way to export the data inside a flex 3 datagrid to an Excel spreadsheet?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
It will not directly export a DataGrid to Excel, but a library called AS3XLS can be used to generate Excel files directly from Flex. See this: http://code.google.com/p/a
You can traverse through the dataProvider of the DataGrid and write to the cells of the Excel file using this component.
Sample Code:
Reading
1. You need to get the Excel file into a ByteArray of some sort, whether by hook, crook, or Embed.
2. Now you need to load it up like so:
var xls:ExcelFile = new ExcelFile();
xls.loadFromByteArray(myBy
1. The sheets are stored in an ArrayCollection as Sheet objects. These hold a bunch of Cell objects each of which has a value property. This returns a Number, a String, or a Date object depending on the contents. You can play with them like so:
var sheet:Sheet = xls.sheets[0];
var value:String = sheet.getCell(0, 0).value;
Each sheet also has a values ArrayCollection suitable for a DataGrid's dataProvider. To display a sheet in a DataGrid you'd do this:
myDataGrid.dataPovider = sheet.values;
Formulas
The result of evaluating a formula is available in the value property. To get the a string representation of the formula, like "SIN(5)" or "A5*SUM(B1:B28)" you use the Formula object:
sheet.getCell(0, 0).formula.formula.
If a cell doesn't contain a formula the formula property will be null.
Writing
First create a sheet and resize it. If you want to resize it after putting in values those values will not be deleted.
var sheet:Sheet = new Sheet();
sheet.resize(10, 10).
Now you can put in some values.
sheet.setCell(0, 0, "Today's date:");
sheet.setCell(0, 1, new Date());
Now put the sheet into an ExcelFile and save it.
var xls:ExcelFile = new ExcelFile();
xls.sheets.addItem(sheet);
var bytes:ByteArray = xls.saveToByteArray();
That ByteArray can be saved to disk and the resulting file will be loadable by any version of Excel.
I guess I'm looking for an easier way, if any. Do you know of a downloadable app I can play with? Again, I need to export data from a flex datagrid into an excel spreadsheet. It is only for local use only and stored on my server for my users who have excel on their machines to download data. I'm not really following the above. I'm kind of a flex 3 newbie.
Okay. It is fairly simple.
1. From the link above, you can download a component in the form of an SWC file.
2. This must be included into your Flex project by putting it in the libs folder.
3. Then, you can write the following in your ActionScript:
var xls:ExcelFile = new ExcelFile(); // if you are using flex builder, typing out this line will automatically import the required libraries
var sheet:Sheet = xls.sheets[0]; // creating a new worksheet
sheet.setCell(0, 0, "Today's date:"); // writing values into the worksheet
// now its just a matter of looping thru the dataProvider of the dataGrid, one row at a time and writing individual values into the worksheet
4. Will be the interesting part, you can convert the Excel object into a ByteArray ..
var xls:ExcelFile = new ExcelFile();
xls.sheets.addItem(sheet);
var bytes:ByteArray = xls.saveToByteArray();
And this ByteArray needs to be sent to the web service which will provide it for download for the user.
// ...
If you are using Adobe AIR then you can directly write this into a file.
I'm not aware of a direct way of DataGrid to Excel export. I know of AS3XLS library and I have worked on server side solutions to this problem in JSP and PHP.
I think ColdFusion has a very easy mechanism of DataGrid to Excel but again that is Server Side programming and not a nqative Flex/ActionScript solution.
I saw this site, http://www.cflex.net/showF
Business Accounts
Answer for Membership
by: mplordPosted on 2009-04-28 at 16:59:35ID: 24256330
I've used an approach based on this solution which works well for me: t.com/2007 /05/export ing-datagr id- data-to -excel.htm l
.com/
http://flex-apollo.blogspo
I can't take any credit for that.
My observations on this approach are:
a) Standard Flex in a web browser has no access to the desktop other than FileReference which won't help you here, so the only way to make anything happen with files that you control the content of on your desktop is via what is possible with the browser, in this case 'downloading' a csv file generated on the fly from a server PHP script containing the data you posted to it.
b) The downside is you have to send your data to the server only for it to return it to you as a download with modified headers to look like an excel file, so you might want to consider security and maybe an HTTPS connection, or some other sort of encryption.
If you want a completely desktop-local solution, you'll have to consider AIR. Then add to that the Flourine solution for system process interaction (Windows only) if you want to e.g. launch files as a desktop process, until Adobe include ability to work with system processes in AIR.
Flourine Aperture: http://aperture.fluorinefx