Skip to main content
Inspiring
October 15, 2014
Question

Adjust column width in tables

  • October 15, 2014
  • 1 reply
  • 750 views

Hi,

Anyone of you please provide the script for the below requirement.

All tables in a document:

1) All ‘$’ columns should be fixed width “1p”

2) All empty column should be “1p”

3) All ‘%’  and ‘)’ column should be “1p”

4) All superscript content column like [1, (1), *] should be “1p”

5) Remaining all columns (except first column) should be “6p” width and values are right aligned

6) First column always variable width

7) All underlines values should be 0.5 bottom border, border only need ‘$’ column and ‘value’ column (not in ‘)’ ‘%’ 1, (1), *) columns.

😎 Also table should be fit within text area (100%)

For example All grey shaded column should be “1p” width and left aligned, All pink shaded column should be “6pica” width and values are right aligned.

I need the below output:

Regards,

Velu

This topic has been closed for replies.

1 reply

Chinnadk
Legend
October 16, 2014

Hi Velu,

Try this,

var doc = app.activeDocument,

    w = doc.documentPreferences.pageWidth;

    sel = doc.selection[0];

if(sel instanceof Table)

{

        var col = sel.columns;

            _left = sel.parent.parentPage.marginPreferences.left;

            _right = sel.parent.parentPage.marginPreferences.right, allcolwidth = 0;

        for(var i=1;i<col.length;i++)

        {

                var cell = col.cells, cont = "";

                for(var j=0;j<cell.length;j++)

                {

                        cont += cell.contents;

                    }

                if(cont == "")

                {

                        col.width = "1p";

                        allcolwidth += col.width;

                    }

                else if(cont.indexOf("$") !=-1)

                {

                        col.width = "1p";

                        allcolwidth += col.width;

                    }

                else

                {

                        col.width = "6p";

                        allcolwidth += col.width;

                        for(var k=0;k<col.cells.length;k++)

                        {

                                if(col.cells.contents !="")

                                {

                                        var paras = col.cells.paragraphs;

                                        for(var l=0;l<paras.length;l++)

                                        {

                                                paras.justification = Justification.RIGHT_ALIGN;

                                            }

                                    }

                            }

                    }

            }

        col[0].width = w - _left - _right - allcolwidth;

    }

else

{

        alert("Select a table...")

    }

Regards,

Chinna

BEGINNER_X
Legend
October 16, 2014

Excellent Stuff Chinna....