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

Align-Center text in 1st column of a table

Engaged ,
Jun 29, 2021 Jun 29, 2021

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 😉

TOPICS
Performance , Scripting
376
Translate
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 ,
Jun 29, 2021 Jun 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 )

Translate
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 ,
Jun 29, 2021 Jun 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;
Translate
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
Engaged ,
Jun 29, 2021 Jun 29, 2021
LATEST

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 !

Translate
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