Copy link to clipboard
Copied
Hello,
I need help. I am working with columns. I need to find the longest character width and create a tabstop aligning (character alignment: ")" ) all the figures to the longest character in the selected column.
This is the unformatted: (in center align)
This is formatted with tab stop: (character align: ")", left-justified)
This is the script that I'm using. It only applies to individual cells so basically, it just center-aligns every cell.
var textsArray = app.selection[0].cells.everyItem().texts.everyItem().getElements();
var tabStopProperties =
{
alignment : TabStopAlignment.CHARACTER_ALIGN ,
alignmentCharacter : ")"
};
for(var n=0;n<textsArray.length;n++)
{
start = textsArray[n].insertionPoints[0].horizontalOffset;
end = textsArray[n].insertionPoints[-1].horizontalOffset;
distance = end - start;
var widthA = app.selection[0].cells[0].width;
var widthB = distance;
var widthC = widthA - widthB;
var widthD = widthC/2
var position = widthA - widthD;
textsArray[n].tabStops.everyItem().remove();
textsArray[n].tabStops.add();
textsArray[n].tabStops[0].properties = tabStopProperties;
textsArray[n].tabStops[0].position = position;
textsArray[n].justification = Justification.LEFT_ALIGN;
};
Thanks,
Martin
Hi Brian!
I think Martin tries to get something like this!
[script written for a client 3 years ago!]
(^/) The Jedi
Copy link to clipboard
Copied
You need to iterate through each cell, not use everyItem in this case. (But I don't know why you just wouldn't use right align for the text and save yourself the trouble?)
var cells = app.selection[0].cells;
for (var i = 0; i < cells.length; i++) {
var texts = cells[i].texts.everyItem().getElements();
...
}
Copy link to clipboard
Copied
Hi Brian!
I think Martin tries to get something like this!
[script written for a client 3 years ago!]
(^/) The Jedi
Copy link to clipboard
Copied
Hi Michel,
This is what I need to achieve. Can you share it with me? Hehe.
-Martin