Legend
July 14, 2025
Question
What's going on here? Can't figure out why: The numbers in the table are centered and left-aligned.
- July 14, 2025
- 2 replies
- 442 views
Hi everyone.
Could you take a look for me?
This script's function:
Centers and left-aligns numbers within tables.
However, for some reason, it works fine when the table fits on a single page.
If the table is too long and spans multiple pages, errors occur.
Additionally, it runs somewhat slowly.
I'm unsure where the error lies.
Thank you very much.

It Prompt:

var doc = app.activeDocument;
var item = doc.selection[0];
app.activeDocument.viewPreferences.rulerOrigin = RulerOrigin.PAGE_ORIGIN;
(function () {
var oColumns = app.selection[0].columns,
i = 0,
rCount = app.selection[0].rows.length,
cCount = app.selection[0].columns.length,
name, lastCell;
for (; i < oColumns.length; i++) {
name = app.selection[0].cells[i].name.split(':');
lastCell = rCount > 1 ? oColumns[i].cells.item(name[0] + ':' + (Number(name[1]) + rCount - 1)) : oColumns[i].cells[-1];
alignMe(oColumns[i].cells.itemByRange(app.selection[0].cells[i], lastCell));
}
function alignMe(c) {
c.paragraphs.everyItem().rightIndent = 0
c.paragraphs.everyItem().leftIndent = 0
c.paragraphs.everyItem().justification = Justification.CENTER_ALIGN;
var offsets = c.paragraphs.everyItem().endHorizontalOffset;
maxOffset = Math.max.apply(null, offsets);
//alert(maxOffset);
c.paragraphs.everyItem().justification = Justification.LEFT_ALIGN;
var newOffset = c.paragraphs[0].endHorizontalOffset;
var nIndent = Math.abs(newOffset - maxOffset);
//alert(nIndent);
c.paragraphs.everyItem().leftIndent = nIndent;
}
})();
