2 Replies Latest reply on Aug 30, 2016 7:40 AM by natrev

    Help Needed!

    natrev Level 3

      Hello Everyone,

       

      I have InDesign table had some values. I need to update that value from CSV document.  
      However, I can't match both CSV value and table content value due to index mark(symbol ::).

      match the value and update the price from CSV.

      Please find the screen shot for your quick reference.

       

      Example:

      I can't match the text 6954 (The text placed in a table) between this symbol :: ::

      Screen Shot 2016-08-30 at 4.17.28 pm.png

       

      CSV data:

      Screen Shot 2016-08-30 at 4.20.02 pm.png

       

      Please advice or suggest me

      Help much appreciated. Thanks in advance.

       

      -VJ

       

      Code:

       

      var flagPrice,flagPageNo,flagUPC,flagQTY;    
      main();
      function main(){
          TableSel=app.selection[0];
          if(TableSel.constructor.name== "Cell"){
              var RowLen=TableSel.rows.length;
              var ColLen=TableSel.columns.length-1;
              var CelLen=TableSel.cells.length;
              var col=0;
              for(i=0;i<RowLen;i++){
                  flagFindSKU=trim(TableSel.cells[i+col].contents).toString();
                  GetDatafromCSV(flagFindSKU);
                  alert(flagFindSKU+"\n"+flagPrice+"\n"+flagPageNo+"\n"+flagUPC+"\n"+flagQTY);
                  col=col+ColLen;                
              }
          }
      }
      function GetDatafromCSV(flagFind){        
          var docRef=app.activeDocument;
          var docPath=app.activeDocument.filePath;
          myFolder=Folder(docPath);
          var myFiles = myFolder.getFiles ("*.csv");
          if(myFiles.length==0){
              myFolder = File.openDialog("Select the CSV file to Proceed");
              if(!myFolder){return;}
              fPathCSV=decodeURI(myFolder);
          }
          fPathCSV=decodeURI(myFiles[0]);        
          var datafile=File(fPathCSV);        
              if (datafile.exists){ 
                  datafile.open('r');
                  while (!datafile.eof){                
                      strLineIn = datafile.readln();
                      colArray = strLineIn.split(",");                
                      if (trim(colArray[0])!="" && trim(colArray[1])!="" && colArray[0]!="sku"){                    
                          alert(colArray[0]+"=="+flagFind);
                          if(trim(colArray[0])==trim(flagFind)){ 
                              flagPrice=parseFloat(colArray[1]);
                              flagPrice=flagPrice.toFixed(2);
                              flagPageNo=colArray[2];
                              flagUPC=colArray[3];
                              flagQTY=colArray[4];      
                              return;
                          }
                      }
                  }
              }
          }
      function trim(str) {
          try{return str.replace(/^\s+/,'').replace(/\s+$/,'');}catch(er) {}
      }