0 Replies Latest reply on Feb 29, 2012 10:18 AM by nikos101

    Help with listToCSV

    nikos101 Level 2

      I have an algorithm that works fine ,except when the text that is added as a csv element has new line characters(makes a jump in the excel) or comma, can anyone give me advice?

       

      Bolded where I think the solution should be

       

      package utils

      {

          import flash.utils.Dictionary;

         

          import mx.collections.IList;

          import mx.utils.ObjectUtil;

       

          /**

           * This class contains static methods to be used to export to various formats

           */

          public class Exporters

          {

       

       

       

              public static function listToCSV(value:IList,delimeter:String):String

              {

                  var str:String='';

       

                 

                  var classInfo:Object=ObjectUtil.getClassInfo(value.getItemAt(0));

                  var properties:Array=classInfo.properties;

                 

                  //get the headers

                  for (var k:int = 0; k < properties.length; k++)

                  {

                      str+=properties[k].toString() + delimeter;

                  }

             

                 

                  str+="\n";

       

                  for each (var o:Object in value)

                  {

                     

                      var prop:*;

                     

       

                      for (var j:int=0; j < properties.length; j++)

                      {

       

                          prop=properties[j];

                          var thing:* = o[prop];

                         

                          var isArray:Boolean=thing is Array;

                          var isDict:Boolean=thing is Dictionary;

                          var isBool:Boolean=thing is Boolean;

                          if (isArray)

                              str+="[]";

                          else if (isDict)

                              str+="{}";

                          else if (isBool)

                                  str+= thing?'YES':'NO';  //everyday users don't like 0 or 1

                          else

                          {

                              str+=  thing  == null?'null': thing.toString() ;

                          }

       

                         

                              str+= delimeter;

                      }

                     

                      str+="\n";

       

       

       

                  }

                  return str;

              }

          }

      }