11 Replies Latest reply on Oct 9, 2015 12:25 PM by tomt27015212

    InDesign Table - Collapse empty Row

    fettergroup

      My apologies if this is not posted in the proper category...


      Ok, here's my issue...


      I have a table with 5 rows.  Sometimes, not all of the rows in the table will contain data.  Is it possible for InDesign to automatically collapse a row if there is no data present in the cells in that row?


      Thanks!

        • 1. Re: InDesign Table - Collapse empty Row
          Jeremy bowmangraphics-DQuh1B Level 3

          The following script should remove any empty rows in all tables in a document:

           

          EDIT: From prior experience, I know it's a better idea to count backwards when deleting, so here is the earlier script with the order reversed:

           

          var myDocument = app.activeDocument;

          for(var i=myDocument.textFrames.length-1; i>=0; i--){

              for(var j=myDocument.textFrames[i].tables.length-1; j>=0; j--){

                  for(var k=myDocument.textFrames[i].tables[j].rows.length-1; k>=0; k--){

                      myContents = 0;

                      for(var l=myDocument.textFrames[i].tables[j].rows[k].cells.length-1; l>=0; l--){

                          if (myDocument.textFrames[i].tables[j].rows[k].cells[l].contents != "") myContents++;

                          }

                      if (myContents == 0) myDocument.textFrames[i].tables[j].rows[k].remove();

                      }

                  }

              }

          • 2. Re: InDesign Table - Collapse empty Row
            fettergroup Level 1

            Thanks for that answer.. I created another post for how I actually utilize this script... Please help if you have any more info!

             

            Thanks!

             

            http://forums.adobe.com/thread/561169

            • 3. Re: InDesign Table - Collapse empty Row
              Jeremy bowmangraphics-DQuh1B Level 3

              Jongware has probably answered this already, but if not:

               

              To run a script in InDesign, copy the code and paste it into

              an ordinary text editor (such as Notepad in Windows), then

              save the file with the extension .jsx in the Scripts Panel Folder

              (typical path: Start > MyComputer > Local Disk(C:) >

              Program Files > Adobe > Adobe InDesign CS3 > Scripts >
              Scripts Panel).

               

               

              script.png

               

              It will then be available from within InDesign (Window > Automation > Scripts).

               

              Yesterday's script removes empty rows from all tables in a document.

              You might find the script below a bit more convenient, as it removes

              empty rows in selected tables (or tables in selected text) only.

               

              To run the script, highlight a table or some text containing a
              number of tables, and then double-click on the name of the script in
              the Scripts panel.

               

               

               

               

               

              var mySelection=app.activeDocument.selection[0];

              try{ var myTableCount = mySelection.tables.length;}

              catch(myError){ var myTableCount = 1;}

              for (var i=myTableCount-1; i >=0; i--) {

              try{ var myTable = mySelection.tables.item(i);}

              catch(myError){var myTable = mySelection; }

              for(var j=myTable.rows.length-1; j>=0; j--){

                          var myContents = 0;

                          for(var k=myTable.rows[j].cells.length-1; k>=0; k--){

                              if (myTable.rows[j].cells[k].contents != "") myContents++;

                              }

                          if (myContents == 0) myTable.rows[j].remove();

                          }

                      }

              • 4. Re: InDesign Table - Collapse empty Row
                jason_haildesign

                Hey Guys I tried to use both these scripts in CS4.

                In both instances, Indesign crashed.

                 

                I have 800+ records of which approx 600 empty cells need to be removed.

                I also tried it selecting a single table and it failed.

                 

                Any advice?

                • 5. Re: InDesign Table - Collapse empty Row
                  timfur

                  I got this to work except that it considered rows that had a column with too wide of text as empty (i.e. there is a date 03/12/11 in a column too wide to hold it, therefore it shows up as a red dot). I need to keep those rows. How would you modify this script to be cautious of that?

                   

                  Thank you,

                  Tim

                  • 6. Re: InDesign Table - Collapse empty Row
                    John Hawkinson Level 5

                    Sure. The script currently increments a variable called "myContents" if there are non-zero contents in the cell:

                     

                    if (myTable.rows[j].cells[k].contents != "") myContents++;
                    

                     

                    And then if myContents is zero, it removes the cell.

                    So you could also increment myContents if the text is overset; just add a line like this after the above:

                     

                    if (myTable.rows[j].cells[k].overflows) myContents++;

                    • 7. Re: InDesign Table - Collapse empty Row
                      bunnyslippers Level 1

                      Jeremy, your script works beautifully. Is it possible to modify it so it works for empty columns instead of rows? I tried doing it myself, but it didn't work (not suprisingly). Thanks

                      • 8. Re: InDesign Table - Collapse empty Row
                        dirks13750554

                        Hello,

                         

                        Nice script, but I have just one problem. The script deleted the blank rows, but the script add for some reasons blank spaces?

                        You will find my pdf here... Any idea?

                         

                        http://www.wallacesanders.be/test.pdf

                        • 9. Re: InDesign Table - Collapse empty Row
                          EBS_houston

                          I'm trying to do the same thing after a data merge, however even if the field appears blank the data merge process leaves an invisible kernel/nugget that is viewed as content. So the row isn't deleted. I've cleared the content of the empty rows and tried the script again and it worked perfectly. Sometimes I will have cells with a zero in them. Anyway to modify this script to seek out and remove the rows with invisible kernels?

                          • 10. Re: InDesign Table - Collapse empty Row
                            tas1971

                            I am having the same issues with the invisible kernals that you are any help would be great

                             

                            thanks,

                            Drew

                            • 11. Re: InDesign Table - Collapse empty Row
                              tomt27015212

                              They're not really invisible, if you Show Hidden Characters and zoom in, you can see they look like a small double colon.  They're kind of hidden behind the "end of story" hashtag/symbol.


                              After spending half the day on this issue I finally found the solutionhttp://indesignsecrets.com/topic/cs5-data-merge-empty-field-character

                               

                              Sure enough, in Find/Change, Text, searching for <feff><feff> and leaving "Change to" empty finally eradicated these buggers!  What a nuisance.  After that, the script runs fine and deletes the empty rows.