2 Replies Latest reply on Nov 19, 2013 10:40 PM by csm_phil

    Read Excel File and Report

    BEGINNER_X Level 3

      Hi All,

       

      I need to match the paragraphs styles with Indesign files and Excel File.

       

      Excel file consists of   standard paragraph styles file naming (around 500 Paragraph Styles)

       

      Indesign files having 100 Paragraphs Styles.

       

      My Request:

       

      I need to generate report if any Indesign paragraph styles that are not in Excel file.

       

      i.e.,

       

      Excel file               Indesign file

      h1                             H1

      h2                              h2

      h3                              BL

      tx                              tx1

      tx1

      tx2

       

      Create Report like:

      Error Paragraph style is  H1 and BL in Indesign file

       

      Created script:

       

       

      var myDoc = app.activeDocument;
      
      var myPstyles = app.activeDocument.allParagraphStyles;
      
      alert("myPstyles: " + myPstyles.length)
      
      for(i=0; i<myPstyles.length; i++)
      {
           var IndesignPStyles = myPstyles[i].name;
          alert(myPstyles[i].name)
          }
      //_____________________________________________________________
      
      //Help Here
      
      var myFile = File.openDialog("Choose a tab delimitted txt file:");
      if (!myFile){
      exit();
      }     
       
      myFile.open('r');
      while (myFile.eof==false){
           line=myFile.readln();
           line = line.split("\t");
           myFind = line[0];
      }
      
      
      

       

      Could anyone help for this request.

       

      Thanks in advance

      Beginner_X

        • 1. Re: Read Excel File and Report
          Learner Learner

          Hi Beginner_x,

           

          I have no idea about reading excel.

           

          try converting you excel to xml and use the below code,

           

              var doc = app.activeDocument;

               var pstyle = doc.allParagaraphStyles;

               var xmlfile = new File("c:\paragraphstyles.xml")

              xmlfile.open('r');

              var content = xmlfile.read();

              var root = new XML(content);

              myFile.open('a');

              for(var i =1;i<pstyle.length;i++){

                  var stylename = pstyle[i].name;

                  var parastyle= (root.xpath("/styles/parastyle[child::text()='"+ stylename+"']")) ;

                  if(parastyle == "" ){

                      myFile.write(pstyle[i].name + '\n');

                  }

              }

          • 2. Re: Read Excel File and Report
            csm_phil Level 4

            Hi BEGINNER_X,

             

            First, you have to convert the excel file into "*.csv or tab delimited" files format. (I use comma delimited file .csv).

             

            You posted in above JS code its read the paragraph style names only. Then another code is read the comma delimited text file only, But you are not compare the paragraph style into excel file list. You missed out here.

             

            Please try the below JS code its working fine, but not generated the report file. I hope you will generate the report file at your end.

             

             

             

            var myFile = File.openDialog("Choose a tab delimitted txt file:");
            if (!myFile){
            exit();
            }     
            
            var myArray = [] 
            myFile.open('r');
            while (myFile.eof==false){
                var line=myFile.readln().split(",");
                myArray.push(line[0]);
                }
            
            var myDoc = app.activeDocument;
            var myPstyles = app.activeDocument.allParagraphStyles;
            
            Array.prototype.contains = function(obj) {
                var i = this.length;
                while (i--) {
                    if (this[i] === obj) {
                        return true;
                    }
                }
                return false;
            }
            
            var myMissingStyle =[];
            for(i=2; i<myPstyles.length; i++){
                var myS =myPstyles[i].name;
                if(myArray.contains(myS) !=true){
                    myMissingStyle.push(myS);
                    }
                }
            
            //I showed only missing styles names, If you want a report file, please you have generate it.
            alert(myMissingStyle.join("\n"));
            

             

             

             

            thx,

            csm_phil