Copy link to clipboard
Copied
Hi, everyone!
I am a beginner in the scripting world and, as I try to study and understand JavaScript, I analyze existing scripts and work a lot with cutting, pasting, and rewriting things.
Recently I put together a functional script to change the color, weight and style of the inner horizontal lines of selected cells of a table. It worked pretty well, but I would like to check if there is more than one cell selected before run the script and I couldn't find a way to do this...
Whenever I try to capture the number of selected cells, the script always returns the value "1", regardless of the quantity. Is there a way to change this behavior? I haven't been able to find any information about it so far, which is why I'm starting my participation here in the community. 🙂
Ps: if I try to change the (selectedCells.length != 0) to (selectedCells.length > 1), it just goes to the second-to-last "else" block.
The code in question is right below.
Thank you in advance for any help!
---
var mySelectedCells = app.selection[0].cells;
Then:
for (var i = 0; i < mySelectedCells.length; i++) {
var myCell = mySelectedCells[i];
...
};
Copy link to clipboard
Copied
If type of your 1st / [0] item of the selection is a "Cell" - then you'll get access to the collection of selected cells like this:
alert(app.selection[0].cells.length);
and then:
alert(app.selection[0].cells[3].contents);
Copy link to clipboard
Copied
Hello, Robert. Thanks a lot for the response!
Actually, I need to make the selection manually because the tables vary too much in size and structure and I just want to know exactly the number of selected cells, not the content itself (just like in the video attached).
I need to select what I want to change and run the script, then the lines are changed.
When I try to return the selection as
$.writeln(selectedCells.length);I always get cell = 1, even though I have 6 cells selected (in the example sent). My intention was just to add another error control that would display an alert if only one cell was selected.
Copy link to clipboard
Copied
var mySelectedCells = app.selection[0].cells;
Then:
for (var i = 0; i < mySelectedCells.length; i++) {
var myCell = mySelectedCells[i];
...
};
Copy link to clipboard
Copied
A little obvious, I would say... But it took me quite a while.
Now I understand my mistake!
Thanks a lot, Robert!
Copy link to clipboard
Copied
You are welcome.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more