3 Replies Latest reply on Jun 28, 2017 1:45 AM by Liphou

    Find Text in Table and Apply Cell Style to Entire Row + Cell Style in Group

    linki87637894 Level 1

      Ok, so I have modified the script found here and it is working correctly.

       

      My script:

      //Front Subheader
      
      var myDoc = app.activeDocument
      
      //var myCell = app.activeDocument.textFrames.everyItem().tables.everyItem().cells.everyItem().getElement s()
      
      app.findTextPreferences = app.changeTextPreferences = null
      
      app.findTextPreferences.findWhat = "FRONT"
      
      var myFound = myDoc.findText()
      
      for(i=0; i<myFound.length; i++)
      {
          if(myFound[i].parent.constructor.name == "Cell")
          {
          myFound[i].parent.appliedCellStyle = "SUBHEADER Cell Style"
        var overrides = myFound[i].clearOverrides()
          }
      }
      

       

      I have two issues however:

       

      1. I want the cell style to apply to the whole row not just the parent cell. I tried changing .parent.constructor.name == "Cell" to .parent.constructor.name == "Row" but that did not work.

       

      2. I want my cell style to be in a group "GENERAL Table Cell Style" and if I put it in there I get an error "46602: A style by that name cannot be found". What would be the separator for the group to the cell style?

       

      Thanks in advance!

        • 1. Re: Find Text in Table and Apply Cell Style to Entire Row + Cell Style in Group
          Chinnadk Level 4

          Try this,

           

          var myDoc = app.activeDocument  
          
          app.findTextPreferences = app.changeTextPreferences = null  
            
          app.findTextPreferences.findWhat = "FRONT"  
            
          var myFound = myDoc.findText()  
            
          for(i=0; i<myFound.length; i++)  
          {  
                  if(myFound[i].parent.constructor.name == "Cell")  
                  {  
                          var parentRowCells = myFound[i].parent.parentRow.cells;
                          for(var j=0;j<parentRowCells.length;j++)
                          {
                                  parentRowCells[j].appliedCellStyle = myDoc.cellStyleGroups.item("GENERAL Table Cell Style").cellStyles.item("SUBHEADER Cell Style");
                             }
                         var overrides = myFound[i].clearOverrides();
                      }  
              }  
          

           

          Regards,

          Chinna

          1 person found this helpful
          • 2. Re: Find Text in Table and Apply Cell Style to Entire Row + Cell Style in Group
            linki87637894 Level 1

            Thanks Chinna that works perfectly.

             

            Is there any way to search for a cell that contains only the word "FRONT" and not cells that contain the word FRONT with other text around it for example FRONT TYRE. At the moment the script is finding these cells too.

             

            Thank you!

            • 3. Re: Find Text in Table and Apply Cell Style to Entire Row + Cell Style in Group
              Liphou Level 1

              Hi,

              Pour le Mots seul FRONT,

               

                 app.findGrepPreferences = app.changeGrepPreferences = null    
                      
                 app.findGrepPreferences.findWhat = "^FRONT$"    
                      
                  var myFound = myDoc.findGrep()  
              

               

              A+

               

              Liphou

              1 person found this helpful