Copy link to clipboard
Copied
This line of Java code
columns [1].
allows me to select that column. However, I need to select, for example, 2, 4, 6. How do I write it?
If I try
columns [2,4,6].
it only takes the 6 and omits the others.
Hi @Mariana TF, I think this would best be explained with code. Please have a look at this, and see what you think. If you are new to coding, it may help to do some tutorials on "for loops". Special methods such as "everyItem" and "getElements" are specific to Indesign, so you will need to look those up in that context. Let me know how you go.
- Mark
/**
* Demonstration of working with specific columns/cells.
* Here we target the body cells from specific columns of every table.
* @author
...
Copy link to clipboard
Copied
InDesign cannot select rows non-consecutively - what you are you trying to do - there might be another way.
Copy link to clipboard
Copied
Hi @Mariana TF, so you want an array that contains whichever columns you choose? How about this:
var columns = myTable.columns;
var myColumns = [columns[2], columns[4], columns[6]];
Does that make sense?
- Mark
Copy link to clipboard
Copied
Mark, thanks.
I tried to integrate your code but my structure needs to be rewritten as
It is giving errors.
Please let me know if I can have a second chance>
My original code was:
app.documents[0].
stories.everyItem().
tables.everyItem().
columns[5].
cells.everyItem().
texts[0].
appliedParagraphStyle =
"Right";
Copy link to clipboard
Copied
As already mentioned - you can't select multiple, non consecutive columns - you need to format them one-by-one - in a loop.
Copy link to clipboard
Copied
Hi @Mariana TF, I think this would best be explained with code. Please have a look at this, and see what you think. If you are new to coding, it may help to do some tutorials on "for loops". Special methods such as "everyItem" and "getElements" are specific to Indesign, so you will need to look those up in that context. Let me know how you go.
- Mark
/**
* Demonstration of working with specific columns/cells.
* Here we target the body cells from specific columns of every table.
* @author m1b
* @discussion https://community.adobe.com/t5/indesign-discussions/how-to-select-columns-and-rows-non-sequentially/m-p/14440216
*/
function main() {
var doc = app.activeDocument;
// make a place to store the cells
var myCells = [];
// get all the tables from document, as array
var tables = doc.stories.everyItem().tables.everyItem().getElements();
// collect cells from the 3rd, 5th and 7th column from each table
for (var i = 0; i < tables.length; i++) {
myCells = myCells
.concat(tables[i].columns[2].cells.everyItem().getElements())
.concat(tables[i].columns[4].cells.everyItem().getElements())
.concat(tables[i].columns[6].cells.everyItem().getElements());
}
// for each collected cell, check if it is
// a body row, and set the paragraph style
for (var i = 0; i < myCells.length; i++) {
if (RowTypes.BODY_ROW === myCells[i].rowType)
myCells[i].cells.everyItem().texts[0].appliedParagraphStyle = "Right";
}
};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Set table column style');
Copy link to clipboard
Copied
Mark, thanks for your time and kindness. Perfect pieces.
I am studying and will get deeper in "everyItem" and "getElements" .
M.
Copy link to clipboard
Copied
 
Copy link to clipboard
Copied
Great to hear! Here is a great article on "everyItem" and "getElements": part 1 and part 2 (by @Marc Autret). They might be too advanced for a beginner to scripting—but keep them in mind for later. Otherwise, just keep scripting and you will learn what you need as you go, and people here will always help if they see you are trying hard.
- Mark
Copy link to clipboard
Copied
Mark, I really appreciate this information.
Your supposition that it was possible to handle this problem, against all odds, has been an encouragement in this area of scripting.
I remember reading some time ago in this forum that someone called a Jongware script a piece of cake. Same here. Thank you. Best regards.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now