Copy link to clipboard
Copied
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)
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 ...
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);
...
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Copy link to clipboard
Copied
HI FRIdNGE!
Thank you very much
This script of yours is running fine.
Learning.......
var cell = app.activeDocument.selection[0].parent;
function selectColumn() {
cell.parentColumn.select();
}
selectColumn();
That's all I know
It can select current column.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Thanks.
It's no response.
I still don't know where to add "select();"
Multiple if else and I'm getting a little dizzy ......
Copy link to clipboard
Copied
Right, sorry.
You've to add this before the last "};":
if (StartRow>0 && EndRow > 0)
{
app.select(myCell.parent.parent.itemByRange(myColumnCells[StartRow], myColumnCells[EndRow]));
};
Copy link to clipboard
Copied
nothing new show up
Copy link to clipboard
Copied
nothing new show up
By @dublove
Right, sorry, replying from my phone.
It should be OK now - please copy the whole code again.
Copy link to clipboard
Copied
Multiple if else and I'm getting a little dizzy ......
By @dublove
In short:
Copy link to clipboard
Copied
Copy link to clipboard
Copied
I updated your new code and it's still not responding.
Copy link to clipboard
Copied
I updated your new code and it's still not responding.
By @dublove
I forgot about using itemByRange() - please check again.
Copy link to clipboard
Copied
Lost.
Don't know where to stop.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
No hints.
I used
alert( “Done! ...” )
Tests don't pop up in many places.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Please look at FRIdNGE''s code.
Shouldn't the next sentence be before {?
if ( myColumnCells[c].appliedCellStyle === myCellStyle )
Copy link to clipboard
Copied
That's what I thought...
My code was a REPLACEMENT of @FRIdNGEs main() function - not a standalone piece of code - you haven't copied the "calling" part from the beginning:
app.doScript("main()", ScriptLanguage.javascript, undefined, UndoModes.ENTIRE_SCRIPT, "To Layout! …");
Without that - my piece of code is just bunch of characters.
Copy link to clipboard
Copied
Look at the code I posted again, patched the top of the FRIdNGE
Shouldn't the next sentence be before {?
if ( myColumnCells[c].appliedCellStyle === myCellStyle )
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++ )
{
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.parent.parent.itemByRange(myColumnCells[StartRow], myColumnCells[EndRow]));
};
};
Copy link to clipboard
Copied
OK, got to my laptop - now it's working - please copy the code again.
But because, you've all "body" rows set as body in thhe Table's applied TableStyle - the whole column - less the header and footer rows - will be selected anyway...
So, what I've suggested earlier - subtractig this info from the total number of rows would make more sense...
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
How to avoid choosing footer?myColumnCells[EndRow-1] ?
By @dublove
But ONLY if you don't have CellsStyles applied directly in your Table.
Like I've said before - you don't have CellStyles applied in your Table - you only have them defined in the TableStyle applied - so they can't be "found" / recognised through checking what CellStyle is applied to the cell.
So this will nevver gonna work.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more