3 Replies Latest reply on Sep 2, 2010 5:32 AM by FOLOF

    How to read Excel file in flex

    Deivamani

      Hi,

           I am new to Adobe flex and i dont know how to read Excel in flex and i need coding for that. So anybody help me...

       

      thanks in advance...

        • 1. Re: How to read Excel file in flex
          flex4 Level 2

          Hi For this u have to write code in java and get the result as arraycollection type from the server  and display in datagrid.. u need to upload the data and get it from ther server or read the excel file  and send to server java file and it will return u an arraycollection object

          • 2. Re: How to read Excel file in flex
            FOLOF

            Hi

             

            You can read and parse XLS files (only works with xls-files) with urlloader and a ZIP-lib that can read zip-files.

             

            public function loadXLS(url:String):void
                    {

                        var urlLoader:URLLoader = new URLLoader();

                        urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
                        urlLoader.addEventListener(Event.COMPLETE, onLoadComplete);
                        urlLoader.load(new URLRequest(url));
                    }
                    private function onLoadComplete(even:Event):void
                    {
                        urlLoader.removeEventListener(Event.COMPLETE, onLoadComplete);
                       
                        model.sheetsDict = new Dictionary();
                       
                        var zipFile:ZipFile = new ZipFile(urlLoader.data);
                       
                        for(var i:int = 0; i < zipFile.entries.length; i++)
                        {
                            var entry:ZipEntry = zipFile.entries[i];
                            var data:ByteArray = zipFile.getInput(entry);
                           
                            if(useFile(entry.name, "/sheet([^$]+)"))
                                model.sheetsDict[entry.name.split("xl/")[1]] = new XML(data.toString());
                            else if( useFile(entry.name, "/sharedStrings.xml") )
                                model.sharedStrings = new XML(data.toString());
                            else if( useFile(entry.name, "/workbook.xml$") )
                                model.workbook = new XML(data.toString());
                            else if( useFile(entry.name, "/workbook.xml.rels") )
                                model.rels = new XML(data.toString());
                        }
                       
                        trace(model.sharedStrings)

             

                    }

             

             

            to read the xml properly you have to use namespaces in the reader-class

             

            namespace ns1 = "http://schemas.openxmlformats.org/spreadsheetml/2006/main";
                    use namespace ns1;
                    namespace ns2 = "http://schemas.openxmlformats.org/officeDocument/2006/relationships";
                    use namespace ns2;
                    namespace ns3 = "http://schemas.openxmlformats.org/markup-compatibility/2006";
                    use namespace ns3;
                    namespace ns4 = "urn:schemas-microsoft-com:mac:vml";
                    use namespace ns4;
                    namespace ns5 = "http://schemas.openxmlformats.org/package/2006/relationships";
                    use namespace ns5;

             

             

             

            //Olof

            • 3. Re: How to read Excel file in flex
              FOLOF Level 1

              Hi again

               

              I forgot to tell you, when you succed to read the xml you have to pair up the words with different ids/columns. I cant remember exactly how its done, but for starters you can unzip a xls-file and lookon the files to figure out how it works.

               

               

              //Olof