Skip to main content
dublove
Legend
February 15, 2025
Answered

Is it possible to only select the cells in a column that have applied "body" cellstyle

  • February 15, 2025
  • 2 replies
  • 1575 views


Sometimes the table is too long, even several pages, you need to exclude the header, continuation, and end of the table, dragging and selecting may be your best way, but it is still a bit cumbersome and troublesome.

What's the best way to do this?
Or a script that selects only the cells in the columns that have the body style applied to them.

After selecting a column, you can perform many operations, and then selecting a row is faster!

 

Thank you very much.

(Attachments available)

 

Correct answer Robert at ID-Tasker

@dublove 

 

This should work:

 

app.doScript("main()", ScriptLanguage.javascript, undefined, UndoModes.ENTIRE_SCRIPT, "To Layout! …");

function main() {

    // Place the Cursor in any Cell:
    var myCell = app.selection[0].parent;
    var myCellStyle = myCell.appliedCellStyle;
    var myColumnCells = myCell.parentColumn.cells;
    var C = myColumnCells.length,  c;
    var myCounter = 0;
    var StartRow = 0;
    var EndRow = 0;
    for ( c = 0; c < C; c++ ) 
    {
//        alert(c);
        if ( myColumnCells[c].appliedCellStyle === myCellStyle ) 
        {
            if (StartRow)
            {
            }
            else
            {
                StartRow = c;
            };
        }
        else
        {
            if (StartRow)
            {
                EndRow = c;
                break;
            };
        };
    };
    if (StartRow > 0 && EndRow == 0)
    {
        EndRow = c;
    };
    if (StartRow>0 && EndRow > 0)
    {
     
   app.select(myCell);
   app.select(myCell.parent.cells.itemByRange(myColumnCells[StartRow], myColumnCells[EndRow]));
    };
};

 

 

Of course you can convert it to a function.

 

2 replies

FRIdNGE
February 15, 2025

Basically, something like that:

 

/*
    _FRIdNGE-0799_ColumnCellsSelectionBasedOnActiveCell.jsx
    Script written by FRIdNGE, Michel Allio [15/02/25]

    See: https://community.adobe.com/t5/indesign-discussions/is-it-possible-to-only-select-the-cells-in-a-column-that-have-applied-quot-body-quot-cellstyle/td-p/15155765
*/

app.doScript("main()", ScriptLanguage.javascript, undefined, UndoModes.ENTIRE_SCRIPT, "To Layout! …");

function main() {

    // Place the Cursor in any Cell:
    var myCell = app.selection[0].parent;
    var myCellStyle = myCell.appliedCellStyle;
    var myColumnCells = myCell.parentColumn.cells;
    var C = myColumnCells.length,  c;
    var myCounter = 0;
    for ( c = 0; c < C; c++ ) if ( myColumnCells[c].appliedCellStyle === myCellStyle ) {
        // Treatment To Be Done:
        myColumnCells[c].fillColor = "red";
        myCounter++
    }

    alert( "On Column " + Number(myCell.parentColumn.index+1) + ": " + myCounter + " Cells")

}

 

This Script will apply a "red" color to all the right cells of a column.

 

(^/)  The Jedi

Robert at ID-Tasker
Legend
February 15, 2025

@FRIdNGE

 

But @dublove wants to SELECT them?

 

If CellStyle is already applied to the cells - what's the point of creating local override? 

 

Robert at ID-Tasker
Legend
February 15, 2025

It all depends on the structure of your table. 

 

If you've it configured "properly" - defined number of header and footer rows - you can use this info to calculate range to select - in script. 

 

If you want to select rows that have specific ParaStyle / CellStyle applied - you need to check every cell in the range you want to select.