flexはexcelをエクスポートして具体的に実現します。


プラグインas 3 xls-1.0.1.swc
 
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Script>
<![CDATA[
import com.as3xls.xls.ExcelFile;
import com.as3xls.xls.Sheet;

import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.controls.CheckBox;

[Bindable]
private var dp:Array = [
{studentID:1,name:"2ssdl",gender:" 001",birthday:"4 ",className:"5 "},
{studentID:2,name:"2 ",gender:"1 ",birthday:"4 ",className:"5 "},
{studentID:3,name:"2 ",gender:"1 ",birthday:" 4",className:" 5"},
{studentID:4,name:" 2",gender:"0 ",birthday:"4 ",className:" 5"},
{studentID:5,name:"2 ",gender:"0 ",birthday:"4 ",className:"5 "}];

private function onCreate(dg:DataGrid):void
{
var rowCount:int = dg.dataProvider.length;
var colCount:int = dg.columnCount;
var sheet:Sheet = new Sheet();
sheet.resize(rowCount+1,colCount); //
var fields:Array = new Array();//
for(var i:int=0; i< colCount;i++)
{
sheet.setCell(0,i,dg.columns[i].headerText.toString());// 0
fields.push(dg.columns[i].dataField.toString());
}
for(var i:int=0; i< rowCount;i++)
{
var record:Object =dg.dataProvider[i];//
insertRecordInSheet(i+1,sheet,record);
}
var excelFile:ExcelFile = new ExcelFile();// excel
excelFile.sheets.addItem(sheet);// excel
var mbytes:ByteArray = excelFile.saveToByteArray();
var file:FileReference = new FileReference();
file.save(mbytes," .xls"); //
file.addEventListener(Event.COMPLETE, function (){
Alert.show(" ");
});
/** **/
function insertRecordInSheet(row:int,sheet:Sheet,record:Object):void
{
for(var c:int; c < colCount; c++)
{
var i:int = 0;
for each(var field:String in fields)
{
for each (var value:String in record)
{
/** myDg record[field] value **/
if (record[field].toString() == value)
/** **/
sheet.setCell(row,i,value);
}
i++;
}
}
}
}
]]>
</fx:Script>
<fx:Declarations>
<!-- ( 、 ) -->
</fx:Declarations>
<mx:Panel>
<mx:Button label=" " click="onCreate(myDG)"/>
<mx:DataGrid id="myDG" width="100%" rowCount="20" dataProvider="{dp}">
<mx:columns>
<mx:DataGridColumn headerText=" " dataField="studentID"/>
<mx:DataGridColumn headerText=" " dataField="name"/>
<mx:DataGridColumn headerText=" " dataField="gender" width="50"/>
<mx:DataGridColumn headerText=" " dataField="birthday" />
<mx:DataGridColumn headerText=" " dataField="className"/>
</mx:columns>
</mx:DataGrid>
</mx:Panel>
</s:Application>
が必要です。