6 Replies Latest reply on Sep 9, 2015 2:52 AM by mkraus514

    A script to apply cell style to entire rows containing a specific text

    Belimisimus*

      Hi,

       

      I am using InDesign CC 2014

       

      Does anyone know how to apply a cellstyle based on text contents found in a cell in javascript?

      I need to search the document and change cell style in entire row to "cellStyle01" if the text "someText" appear in cell.

       

      I've found similar script here in forum which apply table style, but don't know how to change it to apply cell style!

       

      var curDoc = app.activeDocument;
      var allTables = curDoc.stories.everyItem().tables.everyItem();
        
      app.findTextPreferences = app.changeTextPreferences = null;
      app.findTextPreferences.findWhat = "someText";
      var allFounds = allTables.findText();
      app.findTextPreferences = app.changeTextPreferences = null;
        
      for ( var i = 0; i < allFounds.length; i++ ) {
      var curFound = allFounds[i];
      if ( curFound.length == 1 ) {
      var curFoundParent = curFound[0].parent;  
      // curFoundParent.parent.appliedTableStyle = curDoc.tableStyles.itemByName( "tableStyle" );  
      curFoundParent.parent.appliedCellStyle = curDoc.cellStyles.itemByName("cellStyle01");  
      }
      }
      
      

       

      Thanks!