我创建了一个数据网格,还在数据网格之外创建了一些文本框和一个提交按钮。如果我们在文本框中输入了一些数据,然后单击提交按钮,则数据将存储到数据网格中。我想从中导出这些数据数据网格导出到 excel。它是如何可能的?我如何创建一个 excel 表以及它如何与我的数据网格连接?我的代码如下
<?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" minWidth="955" minHeight="600" creationComplete="application1_creationCompleteHandler(event)">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import com.as3xls.xls.Sheet;
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.effects.easing.Exponential;
import mx.events.FlexEvent;
[Bindable]
public var dgItems_client:ArrayCollection = new ArrayCollection();
public var dgItems_admin:ArrayCollection = new ArrayCollection();
public var temp_client:Object = new Object();
public var temp_admin:Object = new Object();
private var fileRef:FileReference=new FileReference;
private var sheet:Sheet;
// public var imagegrid:Image;
private function tabChange():void
{
errorAdmin.visible=false;
errorClient.visible=false;
if(gh.selectedChild.name=='clientTab')
{
details.dataProvider=dgItems_client;
arrayName.headerText="Client_Name";
}
else
{
details.dataProvider=dgItems_admin;
arrayName.headerText="Admin_Name";
}
}
private function submitClick():void
{
if(name_client.text!="" && address_client.text!="" && phone_client.text!="")
{
temp_client = ({Name:name_client.text, Address:address_client.text,Phone_Number:phone_client.text});
dgItems_client.addItem(temp_client);
name_client.text="";
address_client.text="";
phone_client.text="";
clientClick();
errorClient.visible=false;
}
else
{
errorClient.visible=true;
}
if(name_admin.text!=""&&address_admin.text!=""&&phone_admin.text!="")
{
temp_admin = ({Name:name_admin.text, Address:address_admin.text,Phone_Number:phone_admin.text});
dgItems_admin.addItem(temp_admin);
name_admin.text="";
address_admin.text="";
phone_admin.text="";
errorAdmin.visible=false;
}
else
{
errorAdmin.visible=true;
}
}
private function clientClick():void
{
details.dataProvider=dgItems_client;
arrayName.headerText="Client_Name";
}
private function adminClick():void
{
details.dataProvider=dgItems_admin;
arrayName.headerText="Admin_Name";
}
protected function application1_creationCompleteHandler(event:FlexEvent):void
{
fileRef.addEventListener(Event.SELECT,fileSelected);
}
private function fileSelected():void
{
}
private function executeExport():void
{
sheet=new Sheet;
// var dataProviderCollection:ArrayCollection;
var rowCount:int=details.columnsLength;
Alert.show(rowCount.toString());
}
]]>
</fx:Script>
<mx:TabNavigator x="27" y="11" width="455" height="376" id="gh" change="tabChange()" backgroundColor="#A4B6E9">
<s:NavigatorContent width="100%" height="100%" label="Client" id="clientTab">
<s:Label x="10" y="30" width="52" height="25" text="Name:"/>
<s:Label x="10" y="127" width="52" height="28" text="Address:"/>
<s:TextInput id="name_client" x="69" y="18" width="188" height="37" restrict="a-zA-Z"/>
<s:TextArea id="address_client" x="70" y="70" height="126"/>
<s:Label x="10" y="230" width="84" height="32" text="Phone:"/>
<s:TextInput id="phone_client" x="70" y="218" width="188" height="30" restrict="0-9" maxChars="10"/>
<s:Button x="100" y="291" height="28" label="Submit" click="submitClick()"/>
<s:Label id="errorClient" x="59" y="270" width="171" height="27" text="please fill the blank fields" color="red" visible="false"/>
</s:NavigatorContent>
<s:NavigatorContent width="100%" height="100%" label="Admin" id="adminTab" >
<s:Label x="23" y="48" width="52" height="25" text="Name:"/>
<s:Label x="26" y="148" width="52" height="28" text="Address:"/>
<s:TextInput id="name_admin" x="105" y="33" width="188" height="37"/>
<s:TextArea id="address_admin" x="105" y="93" height="126"/>
<s:Label x="26" y="257" width="84" height="32" text="Phone:"/>
<s:TextInput id="phone_admin" x="104" y="246" width="188" height="30" restrict="0-9" maxChars="10"/>
<s:Button x="137" y="305" height="28" label="Submit" click="submitClick()"/>
<s:Label id="errorAdmin" x="100" y="286" width="171" height="17" color="red" fontSize="14"
text="please fill the blank fields" visible="false"/>
<s:Button x="335" y="60" height="34" label="Admin Details" click="adminClick()"/>
<s:Button x="335" y="180" height="34" label="Client Details" click="clientClick()"/>
</s:NavigatorContent>
</mx:TabNavigator>
<s:TitleWindow x="521" y="84" width="377" height="234">
<s:DataGrid x="0" y="0" width="375" height="163" borderVisible="true" id="details">
<s:columns>
<s:ArrayList>
<s:GridColumn dataField="Name" id="arrayName"></s:GridColumn>
<s:GridColumn dataField="Address" headerText="Address"></s:GridColumn>
<s:GridColumn dataField="Phone_Number" headerText="Phone_Number"></s:GridColumn>
</s:ArrayList>
</s:columns>
</s:DataGrid>
<s:Button x="139" y="167" height="28" label="Export" click="executeExport()"/>
</s:TitleWindow>
</s:Application>