5 Replies Latest reply on Jul 2, 2014 12:39 AM by Laubender

    Not all cells in the table getting formatted except just the first one.

    malhar1991 Level 1

      var doc = app.activeDocument,

          _pages = doc.pages, i, j, k, l,

          _textframes, _tables, _row, _cell, rownum;

      for (i = 0; i < _pages.length; i++) {

          _tables = _pages.item(i).Tables;

          for (j = 0; j < _tables.length; j++) {

              _row = _tables.item(i).rows;

              rowlen = _row.length;

              for (k = 0; k < _row.length; k++) {

                  _cell = _row.item(i).cells;

                  for (l = 0; l < _cell.length; l++) {

                      _cell.item(i).appliedCellStyle = "CellA";

                      _cell.item(i).paragraphs.everyItem().appliedParagraphStyle = "ParA";

                  }

              }

          }

      }

       

      Hi, I am stuck in this code. I want to format all the cells in the table but using the above code only the first cell of first row is getting formatted . The other problem is that in all the rows it is couting only one cell. "CellA" and "ParA" are the cell styles and paragraph styles which I made in my pc. I am relatively new to indesign scripting and trying to learn something new.

        • 1. Re: Not all cells in the table getting formatted except just the first one.
          Jump_Over Level 5

          Hi,

          1. There is no ".table" property for "page" so pages.item(i).tables returns error;

          2. Javascript is case sensitive so watch to start a property names with  a small letter ("Tables" is wrong);

          3. There is no need to iterate through pages, tables, rows and cells - just use .everyItem().

           

          so

          app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().appliedCellStyle = "CellA";
          app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().paragraphs.everyItem().appliedParagraphStyle = "ParA";
          

           

          should work.

           

          Jarek

          • 2. Re: Not all cells in the table getting formatted except just the first one.
            TᴀW Adobe Community Professional & MVP

            I can see a few problems:

            First a typo: in line 5 you've written Tables instead of tables

             

            But more fundamentally, a Page object does not have a Table collection

            as one of its properties. So you can't say

             

            pages.item(i).tables

             

            because there is no such thing.

             

            However, various other objects do have tables as properties.

            Specifically, any of the objects that inherit from Text provide access

            to the Table collection (so: text, paragraph, line, word, character,

            insertionPoint, etc.)

             

            Depending on your needs, perhaps the TextFrames object is good for you.

            So, for instance:

             

            myTables = myPage.textFrames.everyItem().tables

             

            will get you a collection of all tables in every text frame on the page

            myPage (not sure if that will include tables in footnotes, or tables

            within tables).

             

            HTH!

            • 3. Re: Re: Not all cells in the table getting formatted except just the first one.
              Laubender Adobe Community Professional & MVP

              (not sure if that will include tables in footnotes, or tables

              within tables).

              @Ariel – no, they are not. Especially tables inside tables are a bit tricky.

              Other "cases": text frames with tables nested to other objects. Or anchored text frames with tables.

               

              So to get all tables inside "regular" stories without seeing "footnotes" or "tables inside cells of other tables" it's best to access document's stories.everyItem().tables.everyItem() .

               

              For getting access to all tables in a document do a TEXT search for the special character that represents a table.

               

              app.findTextPreferences = app.changeTextPreferences = null; 
              
              app.findTextPreferences.findWhat = "<0016>"; 
              var tableCharacters = app.documents[0].findText(); 
              
              var allTablesArray = new Array(); 
              
              for(var n=0;n<tableCharacters.length;n++){ 
                  allTablesArray[n] = tableCharacters[n].texts[0].tables[0]; 
                  };
              
              app.findTextPreferences = app.changeTextPreferences = null;
              

               

              If you are unsure, if the special character <0016> is representing a table object, you could do further tests in the for loop above.

               

              Uwe

              • 4. Re: Not all cells in the table getting formatted except just the first one.
                Jump_Over Level 5

                Hi,

                 

                ...

                Am I invisible...? I mean is post #1 viewed as public?

                ...

                 

                Jarek

                • 5. Re: Re: Not all cells in the table getting formatted except just the first one.
                  Laubender Adobe Community Professional & MVP

                  Hi, Jarek!
                  Of course not !!

                   

                  Forgive me, but I only wanted to answer Ariel's comment.

                   

                  Uwe