9 Replies Latest reply on Jun 25, 2014 9:28 AM by Vick Tantravahi

    Table row automatic apply paragraph style

    Sydney2020

      Hi,

      I'm new in scripting in Indesign. I'd like to write a script for applying a paragraph style to a row in a table like that:

       

      1. Search for the string "XX" in a table

      2. When the string "XX" is found, apply a defined paragraph style named "ParA" to the row which contains the string "XX"

      3. Apply a cell style named "CellA" to the cell which contains the sting "XX"

      4. Apply the paragraph style named "ParB" to the string "XX"

      5. Search for the next string "XX" till the end of the table

       

      Can anybody help me ?

        • 1. Re: Table row automatic apply paragraph style
          Kai Rübsamen Adobe Community Professional

          Your no. 4+5 confuses me. Please provide a example before / after.

          • 2. Re: Table row automatic apply paragraph style
            Sydney2020 Level 1

            Hi Kai,

            Here's en example...

            Thanx for your help.

            script.jpg

            • 3. Re: Re: Table row automatic apply paragraph style
              Chinnadk Level 4

              Hi,

               

              Try this,

               

              var doc = app.activeDocument,
                  _tables = doc.stories.everyItem().textStyleRanges.everyItem().getElements(),
                  i, j, k, l, a, _rows,_cells, rowlen;
              
              
              for(i =0;i<_tables.length;i++)
              {
                  for(j =0;j<_tables[i].tables.length;j++)
                  {
                      _rows = _tables[i].tables[j].rows;
                      for(k =0;k<_rows.length;k++)
                      {
                          _cells = _rows[k].cells;
                          for(l =0;l<_cells.length;l++)
                          {
                              if(_cells[l].contents == "xx")
                              {
                                  rowlen = _cells[l].parent.cells.length;
                                  a = 0;
                                  while(rowlen--)
                                  {
                                        _cells[l].parent.cells[a].paragraphs.everyItem().appliedParagraphStyle = doc.paragraphStyles.item("ParA");
                                        a++;
                                      }
                                  _cells[l].paragraphs.everyItem().appliedParagraphStyle = doc.paragraphStyles.item("ParB");
                                  _cells[l].appliedCellStyle = doc.cellStyles.item("CellA");
                                  }
                              }
                          }
                      }
                   }
              
              
              
              

               

              Regards,

              Chinna

              • 4. Re: Table row automatic apply paragraph style
                Sydney2020 Level 1

                Hy Chinnadk,

                Woks perfectly, thank you very much. How can I adjust that only the selected table is concerned by the script and not all the tables in the file?

                 

                Regards,

                Syd

                • 5. Re: Re: Table row automatic apply paragraph style
                  Chinnadk Level 4

                  Hi Syd,

                   

                  For the selected table use the below one.

                   

                  var doc = app.activeDocument, 
                      _tables = app.selection[0], 
                      i, j, k, l, a =0, _rows,_cells, rowlen; 
                  
                  _rows = _tables.rows; 
                  for(k =0;k<_rows.length;k++) 
                  { 
                      _cells = _rows[k].cells; 
                      for(l =0;l<_cells.length;l++) 
                      { 
                          if(_cells[l].contents == "xx") 
                          { 
                              rowlen = _cells[l].parent.cells.length; 
                              a = 0; 
                              while(rowlen--) 
                              { 
                                    _cells[l].parent.cells[a].paragraphs.everyItem().appliedParagraphStyle = doc.paragraphStyles.item("ParA"); 
                                    a++; 
                                  } 
                              _cells[l].paragraphs.everyItem().appliedParagraphStyle = doc.paragraphStyles.item("ParB"); 
                              _cells[l].appliedCellStyle = doc.cellStyles.item("CellA"); 
                              } 
                          } 
                      } 
                  

                   

                  Regards,

                  Chinna

                  • 6. Re: Table row automatic apply paragraph style
                    Sydney2020 Level 1

                    Hello Chinnadk,

                    Works fine. I will safe a lot of time.

                    Thank you very much.

                     

                    Regards.

                    Syd

                    • 7. Re: Table row automatic apply paragraph style
                      Vick Tantravahi

                      Hey! Can you help me with this ?
                      Is this possible ?

                      BEFORE

                      Screen Shot 2014-06-25 at 11.31.52 AM.png

                      AFTER

                      Screen Shot 2014-06-25 at 11.27.16 AM.png

                      Please someone help me with this!

                      It will save me ages of time.


                      --

                      Vick

                      • 8. Re: Table row automatic apply paragraph style
                        Kai Rübsamen Adobe Community Professional

                        Vick, it is not clear, what is the goal here:

                         

                        1. Is Name 1010, Standard Subheading, Demo >> part of the table. Where can we find those things in the excel screen

                        2. Do you have always the same length of rows > is Percentage always in the 5th row?

                        3. What should happen with those combined cells in row 2+3?

                         

                        I would think, it is helpful, if you can provide your excel file and a idml with a styled example (include table, cell and parastyles!)

                        • 9. Re: Table row automatic apply paragraph style
                          Vick Tantravahi Level 1

                          Its like data from a table in one format should be read and should copy the data into another table with a different formatting settings.

                          can u give your email id ?