10 Replies Latest reply on Oct 30, 2016 3:19 PM by cmoke73

    Tables - using cell-styles

    cmoke73 Level 1

      Hi guys.

       

      I have a table like this:

      screenshot3.JPG

      screenshot4.JPG

       

       

      There is a table-head, a left column and "usual" cells. Now I want to create a table style based on different cell-styles. The style of the first (head) row is different than that of the second. And the first cell of the row ist different as well. How can I create a table-style with those varying styles? One can define cell-styles for: table-head, table-footer, left column, right column and common-cells. But "amount" is a left-cell in a table-head and it is aligned left. The numbers (1,10,50,100) have the same colour but are centered....

        • 1. Re: Tables - using cell-styles
          Scott Falkner Level 5

          You can't. Table Styles are frustratingly limited. If you use a Header or Footer row the Cell Style can only be applied to the entire row. You can define a cell Style for the ”amount” cell but you have to apply it manually.

          • 2. Re: Tables - using cell-styles
            Obi-wan Kenobi Adobe Community Professional

            Apply your "yyy" table style to all tables you want in your doc and just do it! 

             

            var myTables = app.activeDocument.stories.everyItem().tables.everyItem().getElements();  
            for ( var t = 0; t < myTables.length; t++ ) if ( myTables[t].appliedTableStyle.name == "yyy" ) myTables[t].columns[0].cells[0].contents += "\t"; 
            

             

            "Un petit clic vaut mieux qu'une grande claque !"

             

            Capture d’écran 2016-10-30 à 00.50.47.png

             

            (^/)

            • 3. Re: Tables - using cell-styles
              cmoke73 Level 1

              Yeah, I´ve read about the limited options working with tables. Although we enjoy InDesign for more than 17 years there are some basic things doesn´t work. So for exemple auto fit cells. Basicly make tables the most of the problems. Pretty sad.

               

              thank you Scott

              • 4. Re: Tables - using cell-styles
                cmoke73 Level 1

                Okay, I've assumed that I can solve it with a script. But I wanted to avoid it.

                However thanks for the idea Obi-wan

                • 5. Re: Tables - using cell-styles
                  Obi-wan Kenobi Adobe Community Professional

                  Some are called "Table Whisperer" to make them dance!

                   

                  Tables Cells Ajustments In Batch - YouTube

                   

                  (^/)

                  • 6. Re: Tables - using cell-styles
                    Obi-wan Kenobi Adobe Community Professional

                    The script just adds a tab at the end of the first cell of all tables with "yyy" table style applied!

                     

                    That means that if you change the table style "yyy" to another style "xxx", you keep the effect (text apparently aligned on the left, but in fact, always centered)!!

                     

                    … If you have already place the tab, just apply your table style! Nothing else to do!!! 

                     

                    (^/)

                    • 7. Re: Tables - using cell-styles
                      cmoke73 Level 1

                      Okay you wizzard, that was magicly fast.

                      But I think I´ll assign the style manually (only for the left table-head cell).

                      good n8

                      • 8. Re: Tables - using cell-styles
                        Laubender Adobe Community Professional & MVP

                        Obi-wan Kenobi wrote:

                        The script just adds a tab at the end of the first cell of all tables with "yyy" table style applied!

                         

                        Hi Obi-wan,

                         

                        cells[0].contents += "\t";
                        

                         

                        can be quite dangerous. Depending on the nature of contents and formatting that could damage a lot.

                        See the following cell with overset text:

                         

                        1-CellOversetText-Before.png

                        After running your line of code:

                        2-CellOversetText-After.png

                         

                         

                         

                        Wheras if you are working "minimal invasive" with the last insertion point of the cell's Text object the old text is not touched:

                         

                        cells[0].texts[0].insertionPoints[-1].contents = "\t";

                         

                        Also: Your method will remove anchored objects or nested tables and therefore can change formatting of the remaining text.

                        Just a warning…

                         

                        Regards,
                        Uwe

                        • 9. Re: Tables - using cell-styles
                          Obi-wan Kenobi Adobe Community Professional

                          Thanks Uwe for this little tutorial! [I appreciate all comment that makes me learn more!!] 

                           

                          I didn't know you so "mystical" seeing you use "666" Devil sign [Halloween soon of course!  ]. Jedis call it "Sith sign"!!

                           

                          However, the result is not perfect!

                          What is missing is to avoid to process again a cell that already has a tab at its content end!!

                          I didn't find a good syntax to avoid that!

                           

                           

                          var myTables = app.activeDocument.stories.everyItem().tables.everyItem().getElements();  
                          for ( var t = 0; t < myTables.length; t++ ) if ( myTables[t].appliedTableStyle.name == "yyy" ) myTables[t].columns[0].cells[0].texts[0].insertionPoints[-1].contents = "\t"; 
                          

                           

                          (^/)

                           

                          PS: In a first time, I've played inserting after the 2 code lines a Grep research but I don't find this really very interesting! 

                           

                          app.findGrepPreferences = app.changeGrepPreferences = null;
                          app.findGrepPreferences.findWhat = "(\t)+$";
                          app.findGrepPreferences.appliedParagraphStyle = "Header C";
                          app.changeGrepPreferences.changeTo = "$1";
                          app.activeDocument.changeGrep();
                          app.findGrepPreferences = app.changeGrepPreferences = null;
                          
                          • 10. Re: Tables - using cell-styles
                            cmoke73 Level 1

                            Thank you guys!

                            This time I looked for a solution without scripting! But maybe it´s useful for others...