2 Replies Latest reply on Jan 4, 2012 6:09 AM by BJD79

    Can you "Resize Columns: By Scalling to Widths Totalling:" the entire document?

    BJD79 Level 1

      Is it even possible?

       

      Playing with this sample it seems possible but I can't quite figure out how to make it work.

       

       

      var doc =app.ActiveDoc; var flow = doc.MainFlowInDoc; var tbl = 0; var textItems = flow.GetText(Constants.FTI_TblAnchor); for (var i = 0; i < textItems.len; i += 1) { tbl = textItems[i].obj; var tblColWidths = new Metrics (2 * 72 * 65536, 2 * 72 * 65536); tbl.TblColWidths = tblColWidths; }

       

       

      Unlimited amounts of tables in each document for the most part, with 4 to 6 columns each. I'm fairly baffled here, anyone that could help or at least direct me I would appreciate it.

        • 1. Re: Can you "Resize Columns: By Scalling to Widths Totalling:" the entire document?
          OliverJohn Level 2

          The problem is you're only passing widths for two columns, regardless of how many columns the original table has. You'll need to compute the new widths separately for each table. The following code should do what you're looking for:

           

          var flow = app.ActiveDoc.MainFlowInDoc;

          var targetTbleWidth = Math.floor(6.25 * 72 * 65536); // Assumed text frame of 6.25 inches

           

          var tbl;

          var textItems = flow.GetText(Constants.FTI_TblAnchor);

          for (var i = 0; i < textItems.len; i += 1)

          {

                    tbl = textItems[i].obj;

                              scaledColWidths = scaleTblMetrics(tbl, targetTbleWidth)

                              tbl.TblColWidths = scaledColWidths;

                    }

           

          function scaleTblMetrics(tbl, targetWidth)

          {

                    var currentColWidths = tbl.TblColWidths

                    var currentWidth = tbl.TblWidth;

                    var scaleFactor = targetWidth/currentWidth;

                    var targetColWidths = new Metrics;

                    for (var i = 0; i < currentColWidths.length; i++) targetColWidths.push(Math.floor(currentColWidths[i] * scaleFactor));

                    return targetColWidths;

                    }

          • 2. Re: Can you "Resize Columns: By Scalling to Widths Totalling:" the entire document?
            BJD79 Level 1

            I didn't realize it didn't format the code correctly in my orginal post, sorry about that.

             

            You're my hero! I would of never been able to figure this out!