Hi guys,
I’m brand new here, and maybe I’ll gain the “noob of the year” prize because of this post, but now I’ll try to upload a JavaScript code I made this afternoon :)
This code is intended to solve a relatively common problem (at least for me): the numbers in a table column are supposed to be aligned to the right but alltogether they must leave equal free spaces on the left and right sides of the table column.
This script decides which table cells are to be modified and calculates the neccessary right insets for all the selected table cells to create correct number alignments within the selection.
The Javascript code is as follows:
———————————————————————————————–
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(Igazit,ScriptLanguage.JAVASCRIPT,undefined,UndoModes.FAST_ENTIRE_SCRIPT,”Táblázat oszlop”);
function Igazit(){
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;
};
};
———————————————————————————————–
Well, it’s my first, so please do not kill me for it :)