1 Reply Latest reply on Sep 27, 2012 12:42 PM by -hans-

    Apply Table Cell Style Based on Text Search

    ericalm

      Hi, All, Just starting to get my feet wet with scripting for InDesign, but familiar with Javascript and Apple Script in general.

       

      I'm trying to simplify the formatting of a number of tables, converted from Excel (to CSV, GREPed and reformmated in BBEdit, then into ID). While I have already done a lot of scripting for the tables when they're in nice, even columns, once I start merging cells and needing to apply new styles, I'm having to do it all manually again.

       

      I'd like to be able to search for certain text strings (e.g., "Total Credits") in cells, then have the script apply a cell style. I realize this is looking for one thing, then trying to change something else. Is this possible and what functions should I start with? I've been searching here and elsewhere for solutions and poring through my references, but could use some direction at this point.

       

      Thanks!

        • 1. Re: Apply Table Cell Style Based on Text Search
          -hans- Level 4

          Hi, this script does some grepsearch (Numbers in range of 0 -100) in tables and applies cellStyles on results ...

           

          app.findGrepPreferences = NothingEnum.nothing;   
            //[Grep, cellStyleName]
          var grepSearchs = [["\\<[0-5]{1}[0-9]{0,1}\\>|\\<[6-9]\\>", 'Rot'], ["\\<[6-7]{1}[0-9]{1}\\>", 'Gelb'], ["\\<[8-9]{1}[0-9]{1}\\>|\\<100\\>",   'Gruen']]; //0-59 -> Rot ., 60-79 Gelb und 80-100 Grün  
            
          var docTables = app.activeDocument.stories.everyItem().tables.everyItem().getElements();  
            
          o = docTables.length;  
          for(var i = 0; i < o;i++){  
              myTable = docTables[i];  
          l = grepSearchs.length;  
          while(l--){  
          app.findGrepPreferences.findWhat = grepSearchs[l][0];   
          var foundList = myTable.findGrep();   
          f = foundList.length;  
          while(f--){foundList[f].parent.appliedCellStyle = grepSearchs[l][1];}  
          }  
          }  
            
          app.findGrepPreferences = NothingEnum.nothing;
          

           

           

          Hope it'll be of some help

           

          Hans-Gerd Claßen