<?xml version="1.0" encoding="utf-8"?><s:WindowedApplication 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:Declarations><!-- Place non-visual elements (e.g., services, value objects) here --></fx:Declarations><fx:Script><![CDATA[import com.as3xls.xls.ExcelFile;import com.as3xls.xls.Sheet;import mx.collections.ArrayCollection;import mx.controls.Alert;import mx.controls.Image;import mx.core.IVisualElement;private var file:FileReference;private var xls:ExcelFile;var dp:ArrayCollection = new ArrayCollection;/*** 点击文件选择弹出框* */private function upload():void{file = new FileReference();file.addEventListener(Event.SELECT, file_select);file.addEventListener(Event.COMPLETE,file_complete);file.addEventListener(ProgressEvent.PROGRESS,file_progress);file.browse();}/*** 选择了excel之后* */private function file_select (e:Event):void {if (file.size > 0) {file.load();}}/*** excel加载完毕* */private function file_complete (e:Event):void {xls = new ExcelFile();try{xls.loadFromByteArray(e.target.data);}catch(eofe:EOFError){trace(eofe);}var sheet:Sheet = xls.sheets[0];//sheet.rowsdp = sheet.values;dp.removeItemAt(sheet.rows);dg.dataProvider = dp;}/*** 进度条控制* */private function file_progress (e:ProgressEvent):void {progressBar.label = Math.round(100 *e.bytesLoaded / e.bytesTotal) + "%";progressBar.setProgress(Math.round(100 *e.bytesLoaded / e.bytesTotal), 100);}/*** 获取表格数据* */protected function gainDgData(event:MouseEvent):void{var s:String = "";var shuju:ArrayCollection = dg.dataProvider as ArrayCollection;//行数:shuju.source.length-1 范围:0 到 shuju.source.length-2for(var i:uint = 0 ; i < shuju.source.length-1 ; i++){ //一行一行(一条记录一条记录)的遍历//每一行的列数为shuju[i]//s += shuju[i][0].value;}//var t1 = shuju.source.length;}]]></fx:Script><mx:Panel width="800" height="600" layout="vertical" title="上传示例"paddingLeft="20" paddingBottom="20" paddingRight="20"paddingTop="20"><mx:HBox><mx:ProgressBar id="progressBar" minimum="0" maximum="100"/><mx:Button label="上传导入文件" click="upload()"/></mx:HBox><mx:DataGrid id="dg"/><mx:Button label="获取表格数据" click="gainDgData(event)"/><mx:TextArea id="gainData" editable="false"/></mx:Panel></s:WindowedApplication>