Copy link to clipboard
Copied
Hi, I have an ExtendScript question.
When there are connected text frames and one table object straddles both sides, I want to get the cells in the selected text frame.
In your screenshot, you want to get cells 6-10.
What is a good way to do this.
Thanks.
Hi @ajabon grinsmith ,
the short answer is no. You can determine the first frame of the parentTextFrames array.
And that's it. Just like you did this.
The more interesting question would be:
How would you get the text frame if some or all cells in that table are graphic cells?
One idea:
Insert unique labels to every cell of the table.
Use cell.insertLabel( keystring , valuestring ) for this.
Duplicate the text frame you selected.
Then you can determine which cells are in by looking at all
...A table sits in a paragraph. When a table breaks across frames, each line of the table's paragraph contains the part of the table that sits in a frame, and each line is in the first paragraph of each frame. The part of the table that sits in the frame you selected is in your selected frame's first paragraph.
But you don't have direct access to that part. To determine which cells are in the selected frame, you have to get a reference to the whole table, get all the cells, and cycle through them
...Copy link to clipboard
Copied
One idea.
It will take processing time.
If all cells are looped through, the stored text frames can be obtained. Determine if the text frame is selected.
I wonder if there is an approach that uses the text frame as the starting point.
var sel = app.selection[0];
var ary = [];
var cells = app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().getElements();
for(var i = 0; i < cells.length; i++){
if(cells[i].texts[0].parentTextFrames[0] == sel){
ary.push(cells[i]);
}
}
for(i = 0; i < ary.length; i++){
$.writeln(ary[i].texts[0].contents);
}
Copy link to clipboard
Copied
Hi @ajabon grinsmith ,
the short answer is no. You can determine the first frame of the parentTextFrames array.
And that's it. Just like you did this.
The more interesting question would be:
How would you get the text frame if some or all cells in that table are graphic cells?
One idea:
Insert unique labels to every cell of the table.
Use cell.insertLabel( keystring , valuestring ) for this.
Duplicate the text frame you selected.
Then you can determine which cells are in by looking at all cells of the table of that duplicated frame.
Use cell.extractLabel( keystring ) and see what value string is returned.
Keep in mind that tables can come along with header and footer rows.
Regards,
Uwe Laubender
( Adobe Community Professional )
Copy link to clipboard
Copied
Laubender,
Thank you.
I had omitted to tell you that the graphic cell was omitted because it is not used in this project.
The labeling and duplication method has always been the way to go. This is still the most stable and versatile.
Copy link to clipboard
Copied
it will take processing time.
Hi @ajabon grinsmith , seems like you could limit the size of the cell collection by getting the table or tables in the selection’s parentStory, rather than all the document’s tables:
var cells = sel.parentStory.tables[0].cells.everyItem().getElements();
Copy link to clipboard
Copied
rob,
Thank you, you are absolutely right.
But that's like picking a corner of the lunchbox.
What I am looking for now is not the completeness of the sample code, but a means of approaching the cell.
Copy link to clipboard
Copied
And rob.
Your answer did not satisfy me. It is just a frying pan. So I can't give you the correct answer.
I'm done with this question, so I've decided that Laubender's is the correct answer.
Don't be offended. Best regards!
Copy link to clipboard
Copied
A table sits in a paragraph. When a table breaks across frames, each line of the table's paragraph contains the part of the table that sits in a frame, and each line is in the first paragraph of each frame. The part of the table that sits in the frame you selected is in your selected frame's first paragraph.
But you don't have direct access to that part. To determine which cells are in the selected frame, you have to get a reference to the whole table, get all the cells, and cycle through them, checking whether a cell's insertion point's parent text frame is your selected frame. (This is problematic with overset cells, so you should check that first.)
Like this:
frame = app.selection[0];
// Get all the cells in the table
cells = frame.paragraphs[0].tables[0].cells.everyItem().getElements();
sel = [];
// Collect the cells that are in the frame
for (i = 0; i < cells.length; i++) {
if (cells[i].insertionPoints[0].parentTextFrames[0] == frame) {
sel.push (cells[i]);
}
}
// Display the content of the selected cells
for (i = 0; i < sel.length; i++) {
$.writeln (sel[i].contents);
}
P.
Copy link to clipboard
Copied
Peter,
Your view is in line with mine.
As Laubender indicated, the code you provided is most convincing, considering also that the cell is not necessarily a text cell. I will definitely refer to it.
Awesome thanks.