Copy link to clipboard
Copied
I pieced together this script below.
Sorry,It is very difficult for me.
There are several questions for advice:
①How to set the height of all rows of the table to 12mm.
②If the header already exists, then the following two lines will report an error.
How to judge the header that already exists.
--------------------------------------------------------------------------
table.rows[0].rowType = RowTypes.HEADER_ROW;//Set the first line header
myFooterRow.rows.item(-1).rowType = RowTypes.FOOTER_ROW;//Set the last line to the footer
---------------------------------------------------------------------------
table = app.selection[0];
app.selection[0].appliedTableStyle = "mytab";//Apply table style
var myHeaderRow = table.rows[0];
var myNextRow = table.rows[-2];
var myFooterRow = table.rows[-1];
//Set the height of all rows to 10mm;
for (i = 0; i < table.length; i++) {
table.rows[i].height = '12mm';
};
myFooterRow.cells.everyItem().appliedCellStyle = "tab-footer";//Apply cell style
myHeaderRow.cells.everyItem().appliedCellStyle = "tab-header";//Apply header style
table.rows[0].rowType = RowTypes.HEADER_ROW;//Set the first line header
myFooterRow.rows.item(-1).rowType = RowTypes.FOOTER_ROW;//Set the last line to the footer
Thanks
Copy link to clipboard
Copied
"How to set the height of all rows of the table to 12mm."
Hi dublove,
you could address all rows in one go like that:
table.rows.everyItem().height = "12 mm";
Perhaps better, because some cells could contain contents and inset values so that the overall height of a row could differ from the 12 mm you want to apply:
var table = app.documents[0].stories[0].tables[0];
table.rows.everyItem().autoGrow = false;
table.rows.everyItem().height = "12 mm";
Warning: With the code above you will risk overset in cells with even one line of text, if the cell insets plus the necessary height for the text exceed the applied height. Note: There are two undo steps for that code.
FWIW: If you use the properties property to set the values for the exactly same two properties, you need more undo steps. Strange enough, but there is one undo step for every row of the table. Just tested that with InDesign 2020 on Windows 10.
table.rows.everyItem().properties =
{
autoGrow : false ,
height : "12 mm"
};
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
"If the header already exists, then the following two lines will report an error.
How to judge the header that already exists."
There are two properties of the table that indicate the number of header rows and the number of footer rows:
table.headerRowCount
table.footerRowCount
Regards,
Uwe Laubender
( ACP )