0 Replies Latest reply on Sep 18, 2014 9:59 AM by Ferrarezzi

    replace data in csv file

    Ferrarezzi Level 1

      I am creating this script to search the code of the open file and search this code in a csv file and then change the information in this line for the information contained in the open file, but when the array is written to the file, the value is not changed me one can help?

       

      #target illustrator

       

      var sourceDoc = app.activeDocument;

      coletaEspec ()

       

      function coletaEspec (contentEspec){

         

      var myEspec = ["CLIENTE", "COD", "MATERIAL"]

       

      var myDescRev = new Array

      var contentEspec = new Array

       

       

      for ( n = 0 ; n < myEspec.length ; n++ ){

       

       

      var getEspec = myEspec[n]

       

       

      if ( getEspec == "DESC_REV" ){

      var actTxtEspec = sourceDoc.textFrames.getByName(getEspec).contents;

      str = actTxtEspec

       

       

      mySubst = str.replace (/,/g ,".");

       

       

      var nDescRevs = mySubst.split("\r")

       

       

      for ( nD = 0 ; nD < 5 ; nD ++){

      var substituir = nDescRevs[nD]

      try{

      myDescRev.push(substituir)

      }

      catch (e) {

      substituir = " - "

      }

       

       

          }

      substituir = myDescRev

          }

      else{

      var actTxtEspec = sourceDoc.textFrames.getByName(getEspec).contents;

      var substituir  = actTxtEspec.replace (",",".");

      }

      var str = substituir.toString()

      var actEspec = sourceDoc.textFrames.getByName(getEspec);

              if (actEspec.hidden != true){

                  //var y = actTxtEspec.search(",");

                 

                  contentEspec.push(str );

              }

          else {

              contentEspec.push(" - ");

              }

         

          }

       

       

      GetLineArray(contentEspec)

       

       

      }

       

       

      alert("Dados adicionados com sucesso!.");

       

       

      function GetLineArray(contentEspec){

          var textFile = File ("~/Desktop/FORMS/TESTE_SUBSTITUIR_DADOS.csv");

          textFile.open('e');

         

          var myData = textFile.read();

          var iSplitData = myData.split("\n");

         

          var myCod = sourceDoc.textFrames.getByName("COD").contents;

         

          for (i=1; i<iSplitData.length-1; i++) {

       

       

      //alert(iSplitData[i])

       

       

      var myGetData = iSplitData[i].split(",");

       

       

      var myDataCod = myGetData[1].replace (/"/g, '');

       

       

      //alert(myDataCod)

      if ( myDataCod == myCod){

          var linha = i

          alert(iSplitData[i])

          //alert(contentEspec)

          var newContentEspec = contentEspec

         

          alert(newContentEspec)

      alert(iSplitData)

      //var newData = iSplitData.splice(i,1,newContentEspec);

       

       

      var newData = iSplitData.splice(i,1,newContentEspec);

      alert(newData)

       

      textFile.write(newData);

      textFile.close();

       

      break

          }

      }

          }