6 Replies Latest reply on Aug 26, 2014 3:44 AM by Unique

    Find the row contents in CSV File

    Unique Level 1

      Hi Forum,

       

      Im reading the CSV file, and want to find the content on a Cell, which is is below the content "retail" in a header row, and referring the indesign file name which is present at the last column, same row, of the content which is Im finding for.

       

           

      Start DateEnd Datelook and feelMechanicMathingretailSavingAdditional MessagingRMS CODEPA CodeINDD NAME
      17/09/201407/10/2014ValueWantedYes£1"Mr Muscle/Fairy"521381889543126810
      17/09/201407/10/2014NormalWantedYes£1SST521381888443126811
      17/09/201407/10/2014SecondWantedYes£1SST521381889043126812
      17/09/201407/10/2014ThirdNot WantedNo£6SST531981893643126813
      17/09/201407/10/2014FourthSingle orderNo£1SST536981896543126814
      17/09/201407/10/2014FifthDouble orderNo£1SST536981896843126815

       

       

       

      var myFile = File("/Users/studio/Desktop/Workbook.csv");

      if (!myFile){ 

      exit(); 

      }      

       

       

      myFile.open('r'); 

      while (myFile.eof==false){ 

      myFind=myFile.readln(); 

       

      line2 =myFind.split(","); 

      line3 = line2;

       

      myFile.close();

      }

       

       

       

       

      myFile.open('r'); 

      while (myFile.eof==false){ 

           myFile.readln(); 

                line1=myFile.read(); 

       

       

      line1 = line1.split(/['\,\r\n']+/);

       

          NewmyFind = line1;

       

      }

       

       

      for(i=0; i<line3.length; i++) {

          myFind4 = line3[i]; 

       

          for(k=0; k<NewmyFind.length; k++) {

      if(NewmyFind[k]=="43126812"){

      if(myFind4 == "retail" && NewmyFind[myFind4.length-1])

      {

            

      var temp = i;

      lineFinal = [];

       

       

      lineFinal.push(NewmyFind[k][temp]);

      alert (lineFinal);

      }}}}

      myFile.close();

       

       

       

      Can anybody help on this please.

      thanks

        • 1. Re: Find the row contents in CSV File
          Unique Level 1

          Hello Forum,

           

          I just need this really very urgent.

           

          Your help will really save my time.

           

          Can anybody help on the above request.

           

          Many thanks in advance.

          • 2. Re: Re: Find the row contents in CSV File
            Sajeev Sridharan Level 4

            Your code bit confusing...

             

            The below code will search the retail value of INDD NAME..

             

            var myFile = File("/Users/studio/Desktop/Workbook.csv");
            if (!myFile){ 
            exit(); 
            }  
            myFile.open('r'); 
            while (myFile.eof==false)
            { 
                var myFind=myFile.readln(); 
                var myLine =myFind.split(","); 
            
            
                if(myLine[10] == "43126813")
                {
                    alert(myLine[5]);//Retail Value
                }
            }
            

             

             

            P.S.: Always structure your code while posting into the forum

             

            Vandy

            • 3. Re: Re: Re: Find the row contents in CSV File
              Kai Rübsamen Adobe Community Professional

              Vandy, maybe I’m wrong, but I think he wants to alert the name, not the value …

               

              var myFile = File("/Users/studio/Desktop/Workbook.csv");   
              if ( !myFile ) {   
                exit();   
              }    
              myFile.open( 'r' );   
              while ( myFile.eof == false ) {   
                var myFind=myFile.readln();   
                var myLine =myFind.split(",");   
                
                if(myLine[5] == "£6") { 
                  var docName = myLine[10];
                  alert("INDD NAME\r" + docName);
                }  
              }  
              
              myFile.close(); 
              
              • 4. Re: Find the row contents in CSV File
                Unique Level 1

                Hi the two greats,

                 

                Thanks for your this.

                 

                But could you both look at the below script.

                 

                Im trying to get alert of a content ("one") in a cell, which is at the meeting point of the declared contents"found" and "fg". (probably i can say multi-dimentional array method).

                 

                 

                abczdefghjkl
                warnerTRUEimmewarmharm789789
                duplicatefirstsecondthirdfourth123456
                foundfourththreeonetwofront

                 

                 

                I'm finding the content x and content y,  to get the content "one" at their meeting point perpendicularly.

                 

                var file = File("~/Desktop/Book1.csv");

                file.open("r");

                 

                var str = file.read();

                file.close();

                line = str.split(/['\,\r\n']+/);

                 

                 

                mt = [];

                for(i=0;i<line.length; i++){

                  fb = line[i].split(',');

                 

                  for(j=0;j<line.length; j++){

                  sb = line[j].split(',');

                 

                if(fb=="found"){ // Assigning the content"found"

                  if(sb=="fg"){ // Assignin the content "fg"

                  if(j<i) {

                  alert([i]); //it give the length of the cell, but i want to read the content of that cell.

                 

                //  I dont know what to declare here to get the value where value "one" which is perpendicular.

                  }

                }

                }}

                }

                 

                thanks forum.

                • 5. Re: Re: Find the row contents in CSV File
                  Jump_Over Level 5

                  Hi,

                   

                  locate proper index in 1st line ==> go down to proper line ==> grab proper value using index

                   

                  Like below:

                  var
                    csvFile = File("~/Desktop/Book1.csv");
                    columnHead = "fg",
                    rowHead = "found",
                    mResult = findRowColValue(csvFile, columnHead, rowHead);
                  
                  function findRowColValue(csvFile, X_value, Y_value) {
                    // return value from cell found by crossing X_value (column) and Y_value (row)
                    // if wrong X/Y values ==> return false
                    var
                    cLine, cLineArr, xIdx;
                    csvFile.open("r");
                    cLine = "," + csvFile.readln();
                    xIdx = (cLine).search("," + String(X_value) );
                  
                    if (xIdx !=-1) xIdx = cLine.slice(0, xIdx).split(",").length - 1;
                    else return false;
                    // start to read a file from 0 point
                    csvFile.open("r");
                    do {
                    cLineArr = csvFile.readln().split(",");
                    if (cLineArr[0] == Y_value) {
                       csvFile.close();
                       return cLineArr[xIdx];
                       }
                    }
                    while ( !csvFile.eof )
                    csvFile.close();
                    return false;
                    }
                  
                  

                   

                  Jarek

                  • 6. Re: Find the row contents in CSV File
                    Unique Level 1

                    Hi Sir Jarek,

                    Apologisze me for the delayed response.

                     

                    Thanks very very much for the immediate support on my request.

                    YOu pulled me out from the Hell.

                     

                    Extremely a timely help.

                     

                    God bless you.

                     

                    Thanks.