3 Replies Latest reply on Oct 22, 2012 3:04 PM by Trevorׅ

    Find/Change Cell Styles


      I have been searching for a way to find/change cell styles the same way one would find/change character, paragraph, or even object styles.


      My current scenario is in updating a 500-page catalog that contains thousands of price tables located inside text frames. I am currently rebuilding the layouts so the text frames are threaded—but I need a method to expedite applying new table styles (e.g. colored header rows) in addition to clearing overrides for tables that retain the previous formatting. Paragraph & Character styles only get me so far.


      Any guidance on how to write a script that does this?


      Many thanks,



        • 1. Re: Find/Change Cell Styles
          Trevorׅ Adobe Community Professional

          To All


          If the tables have cell styles previously applied to them they should be overridden by either the clearTableStyleOverrides / clearCellStyleOverrides(1) or xmlTable.applyTableStyle(ChangeToTableStyle,1)

          For some reason they are not

          I set up the table styles to apply a cell style so I don't know why the above don't work

          On the UI one can apply the table style and clear the cell styles


          The work around is to set all the cells to "[None]" cell style and then set the table style.  See Bellow scripts

          But what's the proper way to do it?


          Hi Eric
          Do you want to apply the format to all the tables in the doc or only tables which contain cells of a specific cell style?
          The basic steps are to set up the character, paragraph, cell and table styles as desired.
          Make sure that your table style defines which cell styles to use and your cell style defines which paragraph styles to use and so on.
          If you want fomat all the doc tables with the style use


          app.activeDocument.textFrames.everyItem().tables.everyItem().cells.everyItem().appliedCellStyle = "[None]" // change to name of table style

          app.activeDocument.textFrames.everyItem().tables.everyItem().appliedTableStyle = "myTableStyle" // change to name of table style

          app.activeDocument.textFrames.everyItem().tables.everyItem().clearTableStyleOverrides(1); // having problems with the clear overides

          app.activeDocument.textFrames.everyItem().tables.everyItem().cells.everyItem().clearCellStyleOverrides(1); // having problems with the clear overides


          If you want to only format table which contain a specific cell style do set up styles as above and run this.


          // http://forums.adobe.com/thread/1083507?tstart=0
          #target indesign
          app.doScript("main()", ScriptLanguage.javascript, undefined, UndoModes.FAST_ENTIRE_SCRIPT, "Make Index");
          function main()
          var  doc = app.activeDocument,
                  myTables = app.activeDocument.textFrames.everyItem().tables.everyItem().getElements(),
                  l  = myTables.length,
                  findCellStyle = "1", // change name
                  ChangeToTableStyle = "1"; // change name
          while(l-- )
                 var  myCells = myTables[l].cells.everyItem().getElements(),
                 cl  = myCells.length;
                  while(cl-- )
                          if (myCells[cl].appliedCellStyle.name == findCellStyle)
                              cl = false;
                              myTables[l].cells.everyItem().appliedCellStyle = "[None]"; // instead of clearing overrides
                              myTables[l].appliedTableStyle = ChangeToTableStyle;
                              // not clearing overrides ??? why ???
                              myTables[l].cells.everyItem().clearCellStyleOverrides (1);
          function xmlTag(objectToTag) // function not used in script
                if (objectToTag.associatedXMLElement==null)
                    xmlTable = doc.xmlElements [0].xmlElements.add ("myTable" , objectToTag);
                } else
                         xmlTable =doc.xmlElements [0].xmlElements.add ("myTable" , objectToTag);




          1 person found this helpful
          • 2. Re: Find/Change Cell Styles
            e.howes Level 1

            Thanks, Trevor. I found some success with the following:



            app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().clearCellStyle Overrides();

            app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().texts[0].clear Overrides();


            ...of course it applies to all tables in the layout (which is helpful in my case), but see what you think.



            • 3. Re: Find/Change Cell Styles
              Trevorׅ Adobe Community Professional

              Hi Eric,


              What did you those lines not do for you that you need done?


              It seems that you are not using table styles.


              If one was using them one would also use



              My problem is that if the table style says that the cell style should be "cell style 1" and one manually set some of the cell to "cell style 2" I can't get the manually overridden styles to get set to the correct style i.e. "cell style 1" unless I first set them to "None"