Copy link to clipboard
Copied
I am new to InDesign JavaScript scripting. I am importing XML into InDesign tables and want to set the table cell "keep options" to "Keep with next row" via a JavaScript script.
The aim of the script would be to search for a paragraph style, (Head1) in a table and apply "Keep with next row" = "true" creating a new page break.
Any complete examples with a short explanation would be welcome.
There is:
myRow.startRow = StartParagraph.NEXT_FRAME
P.
Copy link to clipboard
Copied
Here you are. Hope it's clear.
// Reset the Find/Change dialog
app.findTextPreferences = null;
// Set the targeted paragraph style
app.findTextPreferences.appliedParagraphStyle = app.activeDocument.paragraphStyles.item ('Head1');
// Find all occurrences of the paragraph style
found = app.activeDocument.findText();
// and go through all found items
for (i = 0; i < found.length; i++) {
// If the found instance is in a cell
if (found.parent instanceof Cell) {
// set the cell's parent row to keep with the next row
found.parent.parentRow.keepWithNextRow = true;
}
}
Peter
Copy link to clipboard
Copied
Hi Peter,
A comment as an aside:
The table widows / orphans management seems apparently only to be included in InDesign as a check box option "Keep lines together" in the "Cell Options", "Rows and Columns" tab. While it would seem to me better that we can choose this in table style itself.
Is there a possibility, via [JS], to check this option globally ("story", document or book) or selecting a table through a kind of dialog: beginning of the table = "2" solidarity lines ; end of the table = "3" lines solidarity? ... Like that exists for paragraphs. And this, whatever styles applied cells [header, footer, current cell].
Once one or all formatted tables, the launch of the script would lock this choice, facilitating the layout [next step], the op no longer having to worry about this.
Thanks in advance for your comment!
Copy link to clipboard
Copied
Sure, such a script wouldn't be too difficult to write.
Copy link to clipboard
Copied
Thanks Peter!
Copy link to clipboard
Copied
Could it be that the script was not working?
Kind regards,
xavier
Copy link to clipboard
Copied
It certainly isn't working. Problem is (as ever) the transfer of the forum messages, which removed indexes. This fragment in the script:
if (found.parent instanceof Cell) {
// set the cell's parent row to keep with the next row
found.parent.parentRow.keepWithNextRow = true;
should be like this (add [i] to 'found' in two instances):
if (found[i].parent instanceof Cell) {
// set the cell's parent row to keep with the next row
found[i].parent.parentRow.keepWithNextRow = true;
P.
Copy link to clipboard
Copied
Yes, I figured it out. Thank you. Is there a javascript command that can automate to start the row on a next frame instead of the option to keep the rows together?
Kind regards,
xavier
Copy link to clipboard
Copied
There is:
myRow.startRow = StartParagraph.NEXT_FRAME
P.
Copy link to clipboard
Copied
Thank you !
Copy link to clipboard
Copied
Hi Peter Kahrel
I have set rows 1 and 2 as the header rows of the table.
Next I want to set: skip the table header row of the 1st text frame.
Please suggest the code to set this in the diagram.
Thanks for your help.
// Convert first row to header and apply cell style
myHeaderRow0.cells.everyItem().appliedCellStyle = "continue";
myHeaderRow1.cells.everyItem().appliedCellStyle = "header";
/*To HEADER
if (myHeaderRow0.rowType !== RowTypes.HEADER_ROW) {
myHeaderRow0.rowType = RowTypes.HEADER_ROW;
}
if (myHeaderRow1.rowType !== RowTypes.HEADER_ROW) {
myHeaderRow1.rowType = RowTypes.HEADER_ROW;
}