Reply To: Table column alignment for numbers

#83796
Tamás Nagy
Participant

Ok, let’s try it again :)

With the pre tag:

if (app.activeDocument.selection.length==0) exit();
if (!app.activeDocument.selection[0].hasOwnProperty("cells")) exit();
var myCtemp=app.activeDocument.selection[0].cells;
if (myCtemp.length==0) exit();

app.doScript(AlignNums,ScriptLanguage.JAVASCRIPT,undefined,UndoModes.FAST_ENTIRE_SCRIPT,"Table Numbers");

function AlignNums(){
var myWo=[], myWt=[], myCells=[], myOi, myTextw;
for (var i=0; i<1000; i++) myWt[i]=0;

for (var i=0; i<myCtemp.length; i++) {
    if (myCtemp[i].rowType!=RowTypes.BODY_ROW) continue;
    myCells.push(myCtemp[i]);
    myOi=myCtemp[i].parentColumn.index;
    myWo[myOi]=myCtemp[i].width;
    myTextw=myCtemp[i].texts[0];
    myTextw=myTextw.endHorizontalOffset-myTextw.horizontalOffset;
    myWt[myOi]=Math.max(myTextw,myWt[myOi]);
    };

for (var i=0; i<myCells.length; i++){
    myOi=myCells[i].parentColumn.index;
    myTextw=(myWo[myOi]-myWt[myOi])/2;
    myCells[i].leftInset=0;
    myCells[i].texts[0].justification=Justification.RIGHT_ALIGN;
    myCells[i].rightInset=myTextw;
    };
};

By the way: how could I delete/modify my earlier posts?

This article was last modified on April 7, 2016

Comments (0)

Loading comments...