Skip to main content
dublove
Legend
May 7, 2026
Question

Is there a more reliable way to determine if two rows are in the same column?

  • May 7, 2026
  • 1 reply
  • 19 views

Because they occupy different numbers of characters, their `horizontalOffset` values are different.
How can I more reliably determine if row 10 and row 1 are in the same column (or the same text box)?

var d = app.activeDocument;
var item = d.selection[0];
tab = item.parent;
var fo = tab.rows[0].cells[0].insertionPoints[0].horizontalOffset
fo = Math.round(fo * 100) / 100;
alert(fo);

 

    1 reply

    m1b
    Community Expert
    Community Expert
    May 7, 2026

    Hi ​@dublove, `horizontalOffset` is for Character, not Cell. Here is a script to show you how to analyze the cells position.

    —Mark

    Example showing 4 cells selected, all in column 0, but spanning across text frames.
    /**
    * @file Show Column and TextFrame or Selected Cells.js
    * @author m1b
    * @version 2026-05-07
    * @discussion https://community.adobe.com/questions-671/is-there-a-more-reliable-way-to-determine-if-two-rows-are-in-the-same-column-1560600?tid=1560600
    */
    (function () {

    var doc = app.activeDocument;
    var cells = doc.selection[0];

    if (!cells || 'Cell' !== cells.constructor.name)
    return alert('Please select one or more cells and try again.');

    // get all the selected cells
    cells = cells.cells.everyItem().getElements()

    var message = 'Selected Cells';

    for (var i = 0; i < cells.length; i++) {

    var cell = cells[i];
    var columnIndex = cell.columns.firstItem().index;
    var rowIndex = cell.rows.firstItem().index;
    var parentTextFrame = getParentTextFrame(cell);

    message += '\n Column ' + columnIndex
    + ' | Row ' + rowIndex
    + ' | Frame ID ' + (parentTextFrame || {}).id;

    }

    alert(message);

    /**
    * Return a row's parent text frame.
    *
    * Notes:
    *
    * (1) Getting the parent text frame of an overset cell is a
    * challenge because there are no insertion points. Here I
    * add a zero-width space as the first character so at least
    * the first insertionPoint will now reside in the text frame.
    *
    * (2) Another complication is a bug where indesign will
    * display the incorrect height for an autogrowing, overflowing
    * cell, and place the cell in the wrong parent text frame.
    * (See explanation here: https://community.adobe.com/t5/indesign-discussions/how-can-get-parenttextframe-of-a-cell-was-overflow/m-p/14030313
    *
    * (3) If your use case is such that returning `undefined` when the
    * cell|row is overset is acceptable, then pass `false` to the
    * `evenWhenCellIsOverset` parameter. This will be much faster.
    *
    * @author m1b
    * @version 2025-04-05
    *
    * @param {Cell|Row} row - an Indesign Table Row or Cell.
    * @param {Boolean} [evenWhenCellIsOverset] - whether to find the parent text frame of an overset cell (default: true).
    * @returns {TextFrame}
    */
    function getParentTextFrame(row, evenWhenCellIsOverset) {

    if (!row.isValid)
    return;

    if (
    false === evenWhenCellIsOverset
    && row.hasOwnProperty('texts')
    )
    // the quick way; will return `undefined` if the cell is overset
    return row.texts[0].parentTextFrames[0];

    if (row.constructor.name == 'Cell')
    row = row.rows[0];

    var cells = row.cells;
    var rowTextFrameIDs = {};
    var rowTextFrame;
    var parentTextFrames = row;

    // find the text frames of the row
    while (
    !parentTextFrames.hasOwnProperty('parentStory')
    || undefined == parentTextFrames.parent
    )
    parentTextFrames = parentTextFrames.parent;

    if (!parentTextFrames.hasOwnProperty('parentStory'))
    return;

    parentTextFrames = parentTextFrames.parentStory.textContainers;

    for (var i = 0; i < cells.length; i++) {

    var cell = cells[i];

    // insert zero-width space to expose first
    // insertion point in case where cell is overset
    cell.insertionPoints[0].contents = '\u200B';

    if (cell.insertionPoints[0].parentTextFrames.length > 0)
    // store the parent frame index of this cell
    rowTextFrameIDs[cell.insertionPoints[0].parentTextFrames[0].id] = true;

    // clean up
    cell.characters[0].remove();

    }

    // match it to the *last-most* parentTextFrame to ensure
    // that the entire row returns the same (correct) text frame
    parentFrameLoop:
    for (var j = parentTextFrames.length - 1; j >= 0; j--) {
    if (rowTextFrameIDs[parentTextFrames[j].id] == true) {
    rowTextFrame = parentTextFrames[j];
    break parentFrameLoop;
    }
    }

    if (
    rowTextFrame != undefined
    && rowTextFrame.isValid
    )
    return rowTextFrame;

    };

    })();

     

    dublove
    dubloveAuthor
    Legend
    May 7, 2026

    Hi ​@m1b 

    This code runs a bit slowly.

    Shouldn't each row have its own offset?

     

    You tested two pages. Try testing the columns on the same page again.
    This 10th row should be Column 1.