flex前台界面导入excel文件的actionscript代码

1、代码如下:

<?xml version="1.0" encoding="utf-8"?>
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" 
				layout="absolute" 
				fontFamily="宋体" 
				fontSize="12" 
				showCloseButton="true" 
				width="754" 
				height="442"
				backgroundSize="100%"
				close="{MyPopupManager.removePopUp(this)}"
			    creationComplete="init()" >
	<mx:Script>
		<![CDATA[
			import com.as3xls.xls.Cell;
			import com.as3xls.xls.ExcelFile;
			import com.as3xls.xls.Sheet;
			
			import flash.events.Event;
			import flash.net.FileFilter;
			import flash.net.FileReference;
			import flash.utils.ByteArray;
			
			import mx.collections.ArrayCollection;
			import mx.controls.Alert;
			import common.actionscript.MyPopupManager;
			
			private var ef:ExcelFile;
			private var ba:ByteArray;
			private var fr:FileReference;
			
			[Bindable] private var statsCollection:ArrayCollection;
			
			
			private function init():void {
				ef = new ExcelFile();
				ba = new ByteArray();
				fr = new FileReference();
				statsCollection = new ArrayCollection();
			}
			
			private function importXLS(e:MouseEvent):void {
				var fileFilter:FileFilter = new FileFilter("Excel (.xls)", "*.xls;*.xlsx;");
				fr.addEventListener(Event.SELECT, selectXLS);
				fr.browse([fileFilter]);
			}
			
			private function selectXLS(e:Event):void {
				fr = FileReference(e.target);
				fr.addEventListener(Event.COMPLETE, fileIn);
				fr.load();
			}
			
			private function fileIn(e:Event):void {
				ba = fr.data;
				ef.loadFromByteArray(ba);
				
				var sheet:Sheet = ef.sheets[0];
				var tCols:int = sheet.cols;
				var tRows:int = sheet.rows;
				
				statusLabel.text = "      " + tCols + " columns; " + tRows + " rows";
				
				//statsCollection = new ArrayCollection();
				
				for(var i:int=1; i<=tRows; i++){
					var statsEntry:Object = new Object();
					statsEntry.TotalEvents1 = sheet.getCell(i,0).value;
					statsEntry.TotalEvents2 = sheet.getCell(i,1).value;
					statsEntry.TotalEvents3 = sheet.getCell(i,2).value;
					statsEntry.TotalEvents4 = sheet.getCell(i,3).value;
					statsEntry.TotalEvents5 = sheet.getCell(i,4).value;
					statsEntry.TotalEvents6 = sheet.getCell(i,5).value;
					
					statsCollection.addItem(statsEntry);
				}
			}
		]]>
	</mx:Script>
	
	<mx:Button x="10" y="10" label="导入Map" click="importXLS(event)"/>
	
	<mx:DataGrid dataProvider="{statsCollection}" x="10" y="39" width="100%" height="100%">
		<mx:columns>
			<mx:DataGridColumn headerText="网络名称" dataField="TotalEvents1" width="140"/>
			<mx:DataGridColumn headerText="相对纬度(X)" dataField="TotalEvents2" width="140"/>
			<mx:DataGridColumn headerText="相对经度(Y)" dataField="TotalEvents3" width="140"/>
			<mx:DataGridColumn headerText="155M互联" dataField="TotalEvents4" width="140"/>
			<mx:DataGridColumn headerText="尾纤互联" dataField="TotalEvents5" width="140"/>
			<mx:DataGridColumn headerText="设备名称" dataField="TotalEvents6" width="140"/>
		</mx:columns>
	</mx:DataGrid>
	<mx:Label x="99" y="10" width="363" height="22" id="statusLabel" />
	
</mx:TitleWindow>  



2、运行结果图:



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值