2 Replies Latest reply on May 19, 2015 7:11 AM by redobs

    Set the same width of all the tables of a document

    redobs Level 1

      Hi everyone. I have a document with a lot of tables (in a 2 columns doc) and want that all that tables have width=90.

      I found here a script from (Dave_Saunders) witch u can set the sith of a selected table, but I need to set for all the talbes of the document (About 700).

      The script from Dave is the one of this post: Tables: Fit Content to Frame

       

      Can anybody help me to automate this change of Tables width.

      Mention that the first cell of all the tables have the same content, the word "Reference".

       

      Thanks in advance!

        • 1. Re: Set the same width of all the tables of a document
          Sajeev Sridharan Level 4

          Try this,

           

          if ((app.documents.length == 0) || (app.selection.length == 0)) { beep() } 
          aDoc = app.activeDocument; 
          tWidth = prompt("Table width", String("000")); 
          for (s=0; s<app.activeDocument.stories.length; s++)
          {
              for (t=0; t<app.activeDocument.stories[s].tables.length; t++)
              {
                  app.activeDocument.stories[s].tables[t].select();
                  aSel = app.selection[0]; 
                  aTable = findTable(aSel); 
                  if ((tWidth == null) || (tWidth == "")) { exit() } 
                  n = aTable.columnCount; 
                  w = aTable.width; 
                  for (j = n-1; j >= 0; j--) { 
                    aTable.columns[j].width = aTable.columns[j].width * (tWidth)/w; 
                  } 
              }
          }
          
          
          function findTable(obj) { 
            if (obj.constructor.name == "Table") { return obj } 
            while (obj.constructor.name != "Table") { 
              obj = obj.parent; 
              if (obj.constructor.name == "Application") { 
                errorExit("Can't locate table"); 
              } 
            } 
            return obj; 
          } 
          
          
          function errorExit(message) { 
            if (arguments.length > 0) { 
              if (app.version != 3) { beep() } // CS2 includes beep() function. 
              alert(message); 
            } 
            exit(); // CS exits with a beep; CS2 exits silently. 
          } 
          
          • 2. Re: Set the same width of all the tables of a document
            redobs Level 1

            It Works really Perfect!!

             

            Thanks a lot!