• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
8

Autofit Rotated Table Cells

Community Expert ,
May 16, 2024 May 16, 2024

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

image.png

TOPICS
How to , Scripting

Views

123

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Beginner , May 20, 2024 May 20, 2024

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!

 

Votes

Translate

Translate
Community Expert ,
May 19, 2024 May 19, 2024

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;

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 20, 2024 May 20, 2024

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 20, 2024 May 20, 2024

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 20, 2024 May 20, 2024

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 20, 2024 May 20, 2024

Copy link to clipboard

Copied

LATEST

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!

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines