Copy link to clipboard
Copied
Hi All,
I have some InDesign tables with rotated heading rows. Is there a way to automatically expand the row height to accomodate overset cells? I am open to a scripting solution if necessary. Thank you.
Rick
Sorry, I wasn't clear. The header was not resizing to the longest content. Instead it was resizing to seemingly random hights. BUT, weirdly, I cannot reproduce it, and now it's working perfectly!
I'd like to add that I'm inmensely thankful to you, Peter Krahel. You've helped me so much over the years! Cheers!
Copy link to clipboard
Copied
You can use something like this:
row = myTable.rows[0];
if (row.cells.everyItem().overflows.join('').indexOf('true') < 0) {
// No overset cells
exit();
}
// Expose all cell content
row.height = '5cm'
// Then size the row to the longest content
top = Math.min.apply (null, row.cells.everyItem().lines.everyItem().insertionPoints[-1].baseline);
row.height = row.cells[0].topInset + row.cells[0].bottomInset + top;
Copy link to clipboard
Copied
Thank you very much!
I've tested with dummy tables, but the math for the resizing part is not working for me... it resizes to strange measures depending on the amount of text, and sometimes it gives me the error "Error String: The property is not applicable in the current state."
Thank you again
Copy link to clipboard
Copied
Thank you Peter. I just needed the row to be just high enough that there would be no overflows, so I used this approach:
#target "indesign"
app.doScript(main, undefined, undefined, UndoModes.entireScript,"Fix Feature Table Header Overflows");
// ======================================================================
function main () {
var tables, count, i, table, row;
tables = app.activeDocument.stories.everyItem ().tables.everyItem ().getElements ();
count = tables.length;
for (i = 0; i < count; i += 1) {
if (tables[i].appliedTableStyle.name === "summary.product") {
// First row of the table.
row = tables[i].rows[0];
while (rowHasOverflows (row) === true) {
row.height = row.height + 1;
}
}
}
}
function rowHasOverflows (row) {
var overflows, count, i;
overflows = row.cells.everyItem ().overflows;
count = overflows.length;
for (i = 0; i < count; i += 1) {
if (overflows[i] === true) {
return true;
}
}
return false;
}
Your test for overflows is more elegant, so I may plug that into my script. Thanks again!
Copy link to clipboard
Copied
@cronban :
> the math for the resizing part is not working for me... it resizes to strange measures
In what way does it not work, and what are 'starnge measures'?
Maybe show one of your tables.
Copy link to clipboard
Copied
Sorry, I wasn't clear. The header was not resizing to the longest content. Instead it was resizing to seemingly random hights. BUT, weirdly, I cannot reproduce it, and now it's working perfectly!
I'd like to add that I'm inmensely thankful to you, Peter Krahel. You've helped me so much over the years! Cheers!