Is there a way to autofit an InDesign table to the size of the text box bounding frame by adjusting row height and/or column width? I am using the script below to delete empty rows from tables, but after deleting the row, the table no longer fills the space it is designed for.
Any suggestions or resources that may be helpful would be very much appreciated!
Thank you!
var rows = app.activeDocument.textFrames.everyItem().tables.everyItem().rows.everyItem().getElements()
for (var i = rows.length - 1; i >= 0; i--) {
if (rows[i].cells.everyItem().contents.toString().replace(/,/g, "") == "")
rows[i].remove()
}
var columns = app.activeDocument.textFrames.everyItem().tables.everyItem().columns.everyItem().getElements()
for (var i = columns.length - 1; i >= 0; i--) {
if (columns[i].cells.everyItem().contents.toString().replace(/,/g, "") == "")
columns[i].remove()
}
Here is the simple solution:
Select the cells you want to resize and run the script. It increases height and width of the selected cells until the cells are fit in the parent text frame.
But it suggests to run the script manually for every problem table. If you mean to change all the tables in the document at once automatically there should be more complicated solution. Let me know if you need it. And it wouldn't hurt if you provide a sample of your document with the tables — there can be details that affect the algorithm.
Update
Here is the 'full-automatic' variant of the script:
It gets all the tables of current document (except hidden layers), select all cells of each table and resize the cells to fit them in their parent text frame.
Not sure, is it okay to change highs of first and second row? Let me know if you don't want change highs of the first two rows.