0 Replies Latest reply on Jun 21, 2011 1:01 AM by rehan3690

    Unable to Import other Excel file




      I'm new to Adobe Flex and learning it now.


      I tried this code its working fine for importing only one excel file


      but the problem is i am unable to import other excel files as i was trying to import other excel files, the first excel file which i had imported appearing in the datagrid




      <?xml version="1.0" encoding="utf-8"?>
      <mx:WindowedApplication   xmlns:s="library.//ns.adobe.com/flex/spark"
                                xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
                  import com.as3xls.xls.ExcelFile;
                  import com.as3xls.xls.Sheet;
                  import com.as3xls.xls.Cell;
                  import flash.net.FileFilter;
                  import flash.net.FileReference;
                  import flash.utils.ByteArray;
                  import mx.collections.ArrayCollection;
                  import flash.events.Event;
                  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 importXL(e:MouseEvent):void{    
                   var fileFilter:FileFilter = new FileFilter("Excel (.xls)","*.xls");
                   fr.addEventListener(Event.SELECT, selectXLS);
                   private function selectXLS(e:Event):void{
                       fr = FileReference(e.target);
                       fr.addEventListener(Event.COMPLETE, fileIn);
                   private function fileIn(e:Event):void{
                       ba = fr.data;
                       var sheet:Sheet = ef.sheets[0];
                       var tCols:int = sheet.cols;
                       var tRows:int = sheet.rows;
                       statuslabel.text = ef.sheets.length + "sheets;" + tCols + "columns;" + tRows + "rows";
                       statscollection = new ArrayCollection();       
                      for(var i:int=1; i<=tRows; i++){
                          var statsEntry:Object = new Object();
                          statsEntry.EventLabel = sheet.getCell(i,0).value;
                          statsEntry.TotalEvents = sheet.getCell(i,1).value;
                          if(statsEntry.EventLabel != ""){
                   private function clearXL():void{
          <mx:Button x="32" y="52" label="Import" click="importXL(event)" id="Importbtn"/>
          <mx:Label x="119" y="54" width="392" id="statuslabel"/>
          <mx:DataGrid x="32" y="131" width="593" height="345" dataProvider="{statscollection}" id="dg">
                  <mx:DataGridColumn headerText="URls" dataField="EventLabel"/>
                  <mx:DataGridColumn headerText="Status" dataField="TotalEvents"/>
          <mx:Button x="34" y="91" label="Clear" click="clearXL()"/>






      In the function "clearXL()" i have tried these but no result




                       // statscollection.removeAll();
                       // dg.dataProvider.removeAll();
                       //  statscollection = null;
                       //  statscollection = new ArrayCollection();



      I didnt get any solution


      Could anyone let me know what to do?





      how can i import Excel 2007 which has an extension xlxs


      Plz help me........