11 Replies Latest reply on Nov 13, 2008 1:27 PM by (Roman_Tarvid)

    Text table issue

    Level 1
      Hi,

      I'm working on a book in InDesing CS3.
      This issue came up when I was palcing Word document into Text frame in
      InDesign CS3.
      The thing is, that my text frame has 120mm width, but Word document has
      Tables that are 100mm wide.
      I thought that Word Tables will stretch automatically to meet the width of
      that Text frame, but it didn't.

      I of course could hold down Shift key and stretch that table proportionally,
      but the thing is that the book is 300 pages long and there are too many
      tables there.

      Can I create some Script (for example) that would stretch 100mm Table witdh
      to
      120mm automatically (proportionally)?


      Thanks in advance,
      R.
        • 1. Re: Text table issue
          Peter Kahrel Adobe Community Professional & MVP
          Try this:

          t = app.activeDocument.stories.everyItem().tables.everyItem().getElements();
          
          for (i = 0; i < t.length; i++)
             {
             c = t[i].columns;
             add = 20 / c.length;
             for (j = 0; j < c.length; j++)
                c[j].width += add;
             }


          Peter
          • 2. Re: Text table issue
            Glen_Bal Level 1
            Peter,

            Your script adds the same amount to every column. I was so free to adapt your script to add a proportional amount to each column.
            Small difference, but i think it is more like the shift-action.

            t = app.activeDocument.stories.everyItem().tables.everyItem().getElements();
            for (i = 0; i < t.length; i++)
            {
            c = t[i].columns;
            newlength = c.length * 1.2;
            for (j = 0; j < c.length; j++)
            c[j].width = newlength;
            }

            Greetz,
            Glen
            • 3. Re: Text table issue
              (Simon_Paterson) Level 1
              For any table in any text frame to be adjusted in the same way as holding shift, try:

              >var myTables = app.activeDocument.stories.everyItem().tables.everyItem().getElements();
              for (var t = 0; t < myTables.length; t++)
              {
              ]var myTableParent = myTables[t].parent;

              var myParentWidth = myTableParent.geometricBounds[3] - myTableParent.geometricBounds[1];

              myTables[t].width = myParentWidth;

              }

              Regards,
              Simon
              • 4. Re: Text table issue
                Level 1
                Simon,

                I hate to break this to you, Simon, but your script doesn't achieve the desired effect. Setting the table width equalizes the space allotted to each column.

                Dave
                • 5. Re: Text table issue
                  (Simon_Paterson) Level 1
                  Hi Dave. I think that is the desired result.
                  • 6. Re: Text table issue
                    (Simon_Paterson) Level 1
                    Just checked his post. I think that is the desired result. He does mention stretching the size of the table proportionally.
                    • 7. Re: Text table issue
                      Peter Kahrel Adobe Community Professional & MVP
                      Glen,

                      >Small difference, but i think it is more like the shift-action.

                      You're quite right, I had missed that. Well spotted & solved.

                      Peter
                      • 8. Re: Text table issue
                        (Simon_Paterson) Level 1
                        Oh, sorry dave, I see what you mean. It doesn't size them proportionally, it changes all columns to the same width. Thank you. My apologies.
                        • 9. Re: Text table issue
                          (Simon_Paterson) Level 1
                          As Dave pointed out, I made a fundamental error. Here is the fixed script which works with any table in any width text frame:

                          >var myTables = app.activeDocument.stories.everyItem().tables.everyItem().getElements();

                          for (var t = 0; t < myTables.length; t++) {
                          ] var myTableWidth = myTables[t].width;

                          var myTableColWidths = myTables[t].columns.everyItem().width;

                          var myTableParent = myTables[t].parent;

                          var myParentWidth = myTableParent.geometricBounds[3] - myTableParent.geometricBounds[1];

                          var myAdjustment = myParentWidth / myTableWidth;

                          for (var c = 0; c < myTables[t].columns.count(); c++) {
                          ]] myTables[t].columns[c].width = myTableColWidths[c] * myAdjustment;
                          ] }

                          }

                          My apologies for the error, and thank you, Dave, for your insight.

                          Note that this only works for one-column frames, however. I'll update it for multi-column frames in a little while.
                          • 10. Re: Text table issue
                            (Simon_Paterson) Level 1
                            Updated for multi-column frames:

                            >var myTables = app.activeDocument.stories.everyItem().tables.everyItem().getElements();

                            for (var t = 0; t < myTables.length; t++) {
                            ] var myTableWidth = myTables[t].width;

                            var myTableColWidths = myTables[t].columns.everyItem().width;

                            var myTableParent = myTables[t].parent;

                            var myParentWidth = myTableParent.textFramePreferences.textColumnFixedWidth;

                            var myAdjustment = myParentWidth / myTableWidth;

                            for (var c = 0; c < myTables[t].columns.count(); c++) {
                            ] {

                            ]] myTables[t].columns[c].width = myTableColWidths[c] * myAdjustment;
                            ] }

                            }
                            • 11. Re: Text table issue
                              Level 1
                              First of all - thank you very much for your kind support.<br />I tested all first 4 posts this morning but couldn't answer to it because <br />something was wrong with my SMTP.<br /><br />I wanted to tell that your script works almost the way it should, but now I <br />see that your updated script is perfect.<br /><br /><br /><br /><Simon_Paterson@adobeforums.com> wrote in message <br />news:59b70481.9@webcrossing.la2eafNXanI...<br />> Updated for multi-column frames:<br />><br />>      var myTables = <br />> app.activeDocument.stories.everyItem().tables.everyItem().getElements();<br />>      for (var t = 0; t < myTables.length; t++) {<br />><br />>        var myTableWidth = myTables[t].width;<br />>        var myTableColWidths = myTables[t].columns.everyItem().width;<br />>        var myTableParent = myTables[t].parent;<br />>        var myParentWidth = <br />> myTableParent.textFramePreferences.textColumnFixedWidth;<br />>        var myAdjustment = myParentWidth / myTableWidth;<br />>        for (var c = 0; c < myTables[t].columns.count(); c++) {<br />><br />>        {<br />><br />>          myTables[t].columns[c].width = myTableColWidths[c] * <br />> myAdjustment;<br />><br />>        }<br />><br />>      }<br />>