Skip to main content
Fred.L
Inspiring
June 29, 2021
Question

Align-Center text in 1st column of a table

  • June 29, 2021
  • 2 replies
  • 403 views

Hi guys,
I'm trying to save some time by using a script that'll work on tables but I'm facing a problem on 1 line.

I would like to Center the text of the first column, without using any paraphStyle.

Here is part of it.

   table.cells.everyItem().clearCellStyleOverrides(true);
   table.appliedTableStyle = "Main Table";

   table.cells.everyItem().leftInset = table.cells.everyItem().rightInset = "1.411 mm";
   table.cells.everyItem().topInset = table.cells.everyItem().bottomInset = "1.411 mm";
   table.cells.everyItem().verticalJustification = VerticalJustification.CENTER_ALIGN;
   table.columns[0].width = "10";
   table.columns[1].width = "76";

    //table.columns[0].cells.everyItem()... (what about here ??) ... Justification.CENTER_ALIGN;

    table.cells.everyItem().autoGrow = true;
    table.cells.everyItem().minimumHeight = "1.058 mm";

My challenge here is to fill the gap at the line

//table.columns[0].cells.everyItem()... (what about here ??) ... Justification.CENTER_ALIGN;

 

Any help will be appreciated 😉

This topic has been closed for replies.

2 replies

brian_p_dts
Community Expert
Community Expert
June 29, 2021

To target all cells in the first column of a table, it's:

table.columns[0].cells.everyItem().texts[0].justification = Justification.CENTER_ALIGN;
Fred.L
Fred.LAuthor
Inspiring
June 29, 2021

Thank you guys, I was definitely missing something …
I thought I needed to get around it with Texts/ appliedStyles and so on. It turns out to be far simpler.

Thanks a lot ^^ works as a charm !

Community Expert
June 29, 2021

Are you missing texts[0] ?

Be careful with everyItem() . Could crash your script or InDesign itself if some conditions are not met.

Take for example this line, that should remove the last row of every table in the document:

 

app.documents[0].stories.everyItem().tables.everyItem().rows[-1].remove();

 

That would crash InDesign if it happens that there is a table with only one header row and one single body row.

 

Regards,
Uwe Laubender

( ACP )