国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 開發(fā) > Flex > 正文

flex導(dǎo)出excel具體實(shí)現(xiàn)

2024-09-08 18:16:58
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
需要插件 as3xls-1.0.1.swc

復(fù)制代碼 代碼如下:


<?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區(qū)",className:"5清道夫卻無(wú)法"},
{studentID:2,name:"2士大",gender:"1色調(diào)",birthday:"4卻",className:"5為去去"},
{studentID:3,name:"2訪問",gender:"1色調(diào)",birthday:"飛4",className:"訪問5"},
{studentID:4,name:"訪問2",gender:"0色調(diào)",birthday:"4卻",className:"為5"},
{studentID:5,name:"2各位",gender:"0色調(diào)",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); //設(shè)置表格的范圍
var fields:Array = new Array();//用來(lái)保存字段
for(var i:int=0; i< colCount;i++)
{
sheet.setCell(0,i,dg.columns[i].headerText.toString());//表格第0行設(shè)置字段名
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,"測(cè)試文件.xls"); // 定死文件名
file.addEventListener(Event.COMPLETE, function (){
Alert.show("保存成功");
});
/**回調(diào)函數(shù)**/
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)
{
/**循環(huán)判斷myDg列名域值record[field]與value是否相等**/
if (record[field].toString() == value)
/**寫入表格中**/
sheet.setCell(row,i,value);
}
i++;
}
}
}
}
]]>
</fx:Script>
<fx:Declarations>
<!-- 將非可視元素(例如服務(wù)、值對(duì)象)放在此處 -->
</fx:Declarations>
<mx:Panel>
<mx:Button label="導(dǎo)出"/>
<mx:DataGrid rowCount="20" dataProvider="{dp}">
<mx:columns>
<mx:DataGridColumn headerText="學(xué)號(hào)" dataField="studentID"/>
<mx:DataGridColumn headerText="姓名" dataField="name"/>
<mx:DataGridColumn headerText="性別" dataField="gender"/>
<mx:DataGridColumn headerText="生日" dataField="birthday" />
<mx:DataGridColumn headerText="班級(jí)" dataField="className"/>
</mx:columns>
</mx:DataGrid>
</mx:Panel>
</s:Application>

(編輯:武林網(wǎng))

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 教育| 宝山区| 金乡县| 日土县| 永济市| 梨树县| 出国| 潞西市| 新和县| 五家渠市| 新巴尔虎右旗| 错那县| 苏尼特左旗| 昌吉市| 尉犁县| 龙井市| 温州市| 东港市| 桂阳县| 东丽区| 西平县| 班玛县| 连城县| 巴马| 延寿县| 康乐县| 平顺县| 紫金县| 镇原县| 盐池县| 桃源县| 辰溪县| 漳州市| 中方县| 准格尔旗| 宝鸡市| 波密县| 德阳市| 宁陵县| 临沭县| 乐山市|