校园春色亚洲色图_亚洲视频分类_中文字幕精品一区二区精品_麻豆一区区三区四区产品精品蜜桃

主頁 > 知識庫 > flex導出excel具體實現

flex導出excel具體實現

熱門標簽:廣州ai外呼系統業務 車載電話機器人 天津企業外呼系統代理商 南昌crm外呼系統如何 外呼系統號碼顯示 什么行業需要電話機器人 地圖標注多家店 無錫電銷外呼系統代理 中山外呼系統中間件
需要插件 as3xls-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>

標簽:欽州 泰州 滄州 佛山 仙桃 海西 呂梁 攀枝花

巨人網絡通訊聲明:本文標題《flex導出excel具體實現》,本文關鍵詞  flex,導出,excel,具體,實現,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《flex導出excel具體實現》相關的同類信息!
  • 本頁收集關于flex導出excel具體實現的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 克山县| 翁源县| 牙克石市| 宜丰县| 枣强县| 葫芦岛市| 临城县| 长春市| 汾阳市| 岳西县| 屏东市| 清徐县| 榆社县| 疏附县| 高青县| 富裕县| 五原县| 汝阳县| 陆良县| 邯郸市| 西充县| 双柏县| 芜湖县| 平果县| 宜宾市| 安平县| 玉田县| 盐山县| 铜鼓县| 报价| 金川县| 宜君县| 杂多县| 富源县| 策勒县| 丽江市| 东光县| 奇台县| 密山市| 霞浦县| 桑日县|