2 Replies Latest reply on Dec 29, 2009 4:28 AM by nikos101

    goggle export of contacts in csv forma

    nikos101 Level 2

      Hi, I'm looking for some code that could help me in parsing an imported string (via readUTFBytes)of a  goggle export of contacts in csv format. I would like to put each contact into a row in an ArrayCollection

        • 1. Re: goggle export of contacts in csv forma
          nikos101 Level 2

          I found this code from http://www.sitepoint.com/forums//showthread.php?t=572709# but it doesn't work to good

           

          var properties:Array = new Array();
                          var headings:Boolean = false;
                          var carriage:Number = new Number();
                          var comma:Number = new Number();
                          var cursor:Number = new Number();
                          var sub:Number = new Number();
                          var item:Object = new Object();
                          var value:String = new String();
                          var line:String = new String();
                          var contacts:Array = new Array();   
                         
                          var result:String = file.data.readUTF();
                         
                          while( result.indexOf( "\n", cursor ) != -1 ) {
                              carriage = result.indexOf( "\n", cursor );
                              line = result.substring( cursor, carriage );
                             
                              cursor = 0;
                              sub = 0;
                             
                              item = new Object();
                             
                              while( line.indexOf( ",", cursor ) != -1 ) {
                                  comma = line.indexOf( ",", cursor );
                                  value = line.substring( cursor, comma );
                                 
                                  if( !headings ) {
                                      properties.push( value );
                                  } else {
                                      item[properties[sub]] = value;
                                      //trace("email:\n" + value.toString());
                                  }
                                 
                                  cursor = comma + 1;
                                  sub++;
                              }
                             
                              value = line.substring( cursor, line.length - 1 );
                             
                              if( !headings ) {
                                  properties.push( value );
                                  headings = true;
                                  //trace("headings:\n" + value.toString());
                              } else {
                                  item[properties[sub]] = value;
                                  contacts.push( item );
                                  //trace("contact:\n" + item.Name.toString());
                              }
                                 
                          }

          • 2. Re: goggle export of contacts in csv forma
            nikos101 Level 2

            I've managed like this:

             

                private function completeHandler(event:Event):void {
                           
                           
                            var result:Array = file.data.readUTF().split('\n');
                            var headers:Array = result[0].split(',');
                            //var count:uint =  headers.length;
                           
                            for(var i:uint=1;i<result.length;i++){
                                var o :Object = new Object;
                                var data:Array = result[i].split(',');
                                for(var j:uint=0;j<headers.length;j++){
                                   
                                    o[headers[j]]= data[j];
                                }
                                arrayC.addItem(o);
                            }
                           
                        }

             

             

            However when parsing the following text


            First Name,Middle Name,Last Name,Title,Suffix,Initials,Web Page,Gender,Birthday,Anniversary,Location,Language,Internet Free Busy,Notes,E-mail Address,E-mail 2 Address,E-mail 3 Address,Primary Phone,Home Phone,Home Phone 2,Mobile Phone,Pager,Home Fax,Home Address,Home Street,Home Street 2,Home Street 3,Home Address PO Box,Home City,Home State,Home Postal Code,Home Country,Spouse,Children,Manager's Name,Assistant's Name,Referred By,Company Main Phone,Business Phone,Business Phone 2,Business Fax,Assistant's Phone,Company,Job Title,Department,Office Location,Organizational ID Number,Profession,Account,Business Address,Business Street,Business Street 2,Business Street 3,Business Address PO Box,Business City,Business State,Business Postal Code,Business Country,Other Phone,Other Fax,Other Address,Other Street,Other Street 2,Other Street 3,Other Address PO Box,Other City,Other State,Other Postal Code,Other Country,Callback,Car Phone,ISDN,Radio Phone,TTY/TDD Phone,Telex,User 1,User 2,User 3,User 4,Keywords,Mileage,Hobby,Billing Information,Directory Server,Sensitivity,Priority,Private,Categories

             

            The First Name field gets renamed to rst Name When split out of the header array, I can't figure out why