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

    Unable to Import other Excel file

    rehan3690

      Hi,

       

      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()">
         
         
          <mx:Script>
          <![CDATA[
                  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);
                   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 = 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 != ""){
                         
                          statscollection.addItem(statsEntry);
                          }
                         
                      }
                              
                      
                   }
                  
                   private function clearXL():void{
                      
                      
                        dg.dataProvider.removeAll();
                          
                   }
             
          ]]>
      </mx:Script>
          <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:columns>
                  <mx:DataGridColumn headerText="URls" dataField="EventLabel"/>
                  <mx:DataGridColumn headerText="Status" dataField="TotalEvents"/>
              </mx:columns>
          </mx:DataGrid>
          <mx:Button x="34" y="91" label="Clear" click="clearXL()"/>
         
             
      </mx:WindowedApplication>

       

       

       

       

       

      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?

       

       

      and

       

      how can i import Excel 2007 which has an extension xlxs

       

      Plz help me........