4 Replies Latest reply on Sep 9, 2015 4:10 AM by FiLiP

    How to apply a table cell style based on grep search?

    andreasf Level 1

      Anyone that know how to make a script that searches in an Indesign table for

       

      -> All cells where the text starts with "Banana"

      -> And apply cell style "Yellow" to these cells?

       

       

      I have been searching on forums for somedays and got this tip: https://github.com/seuzo/regex_cellstyle/blob/master/regex_cellstyle.jsx

      -> But that script is in japanese and also use dialogs.

       

      All help most appriciated!

        • 1. Re: How to apply a table cell style based on grep search?
          BEGINNER_X Level 3

          Hi Frankeman,

           

          Please try the below code, may it should be helpful:

           

          var myDoc = app.activeDocument

          app.findTextPreferences = app.changeTextPreferences = null

          app.findTextPreferences.findWhat = "Banana"

           

          var myFound = myDoc.findText()

           

          for(i=0; i<myFound.length; i++)

          {

              if(myFound[i].parent.constructor.name == "Cell")

              {

             

             myFound[i].parent.appliedCellStyle = "Yellow"

           

              }

          }

           

          Suppose the code is working fine for you, then please click correct answers.

           

          thanks

          Beginner_X

          1 person found this helpful
          • 2. Re: How to apply a table cell style based on grep search?
            andreasf Level 1

            Almost there!

             

            The script applies the correct cell style but with overrides.

             

            -> See attached file.

            -> Any way to make a script that clears all overrides?

             

            OVERRIDES.png

            • 3. Re: How to apply a table cell style based on grep search?
              BEGINNER_X Level 3

              Hi Frankemans,

               

              var myDoc = app.activeDocument

              app.findTextPreferences = app.changeTextPreferences = null

              app.findTextPreferences.findWhat = "Banana"

              var myFound = myDoc.findText()

              for(i=0; i<myFound.length; i++)

              {

                  if(myFound[i].parent.constructor.name == "Cell")

                  {

               

                 myFound[i].parent.appliedCellStyle = "Yellow"

                    var overrides = myFound[i].clearOverrides()          //this is the new line added in this content

                 

                  }

              }

               

              Thanks

              Beginner

              • 4. Re: How to apply a table cell style based on grep search?
                FiLiP Level 1

                Hi guys I'm looking for something like this. I've found and used executable scripts before, but have never 'programmed one' and put it into InDesign using code like the one above. i'm using CS5.5 on a windows machine. Could anyone let me know what to do or point me in the direction of a post explaining? many thanks

                Grebe