Quantcast
Channel: Adobe Community : Popular Discussions - InDesign Scripting
Viewing all articles
Browse latest Browse all 15932

Fix Column width in tables

$
0
0

Hi,

 

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

 

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[i].cells, cont = ""; 

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

                    { 

                            cont += cell[j].contents; 

                        } 

                    if(cont == "") 

                    { 

                            col[i].width = "1p"; 

                            allcolwidth += col[i].width; 

                        } 

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

                    { 

                            col[i].width = "1p"; 

                            allcolwidth += col[i].width; 

                        } 

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

                    { 

                            col[i].width = "1p"; 

                            allcolwidth += col[i].width; 

                           

                        } 

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

                    { 

                            col[i].width = "1p"; 

                            allcolwidth += col[i].width; 

 

                        } 

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

                    { 

                            col[i].width = "1p"; 

                            allcolwidth += col[i].width; 

 

                        } 

            

                    else 

                    { 

                            col[i].width = "5p"; 

                            allcolwidth += col[i].width; 

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

                            { 

                                    if(col[i].cells[k].contents !="") 

                                    { 

                                            var paras = col[i].cells[k].paragraphs; 

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

                                            { 

                                                    paras[l].justification = Justification.RIGHT_ALIGN; 

                                                } 

                                        } 

                                } 

                        } 

                } 

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

        } 

    else 

    { 

            alert("Select a table...") 

        }

 

All tables in a document:

 

1) All $, %, ), columns should be fixed width “1p”

2) All empty column should be “1p”

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

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

5) First column always variable width

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

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

 

The below script is working fine but it missed the requirements for (point no 3 and 6).


Sometimes empty columns are not converted into "1p" because of spanning (see the below table), Can you please ignore the spanned columns while running the script or put any input dialogue box for "number of rows to ignore".


input.JPG


Viewing all articles
Browse latest Browse all 15932