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

script to adjust the width of column

Participant ,
Sep 12, 2017 Sep 12, 2017

need a script to set width of below column .ie 30, 45, 60, 15, 15, 30, and 30 for the table, thanks in advance

TOPICS
Scripting
4.9K
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

correct answers 1 Correct answer

Advocate , Nov 20, 2017 Nov 20, 2017

First find your table and store in myTable variable, and you can directly assign value to each column just like this...

for(var i = 0; i< myTable.columns.length; i++){

     if(i==0){

          myTable.columns.width = 30;

          }

     else if(i==1){

          myTable.columns.width = 45;

          }

     else if(i==2){

          myTable.columns.width = 60;

          }

     else if(i==3){

          myTable.columns.width = 15;

          }

     else if(i==4){

          myTable.columns.width = 15;

          }

   

...
Translate
Community Expert ,
Sep 12, 2017 Sep 12, 2017

This script still works in CC2017 - it not only lets you set specific column widths, but also lets you save them to a table style so that you can apply them automatically to subsequent tables that have that style applied. 

Re: column width in cell specs

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
Adobe Employee ,
Nov 20, 2017 Nov 20, 2017

moved to InDesign Scripting​

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
Advocate ,
Nov 20, 2017 Nov 20, 2017

First find your table and store in myTable variable, and you can directly assign value to each column just like this...

for(var i = 0; i< myTable.columns.length; i++){

     if(i==0){

          myTable.columns.width = 30;

          }

     else if(i==1){

          myTable.columns.width = 45;

          }

     else if(i==2){

          myTable.columns.width = 60;

          }

     else if(i==3){

          myTable.columns.width = 15;

          }

     else if(i==4){

          myTable.columns.width = 15;

          }

     else if(i==5){

          myTable.columns.width = 30;

          }

     else if(i==6){

          myTable.columns.width = 30;

          }

     }

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
Guide ,
Nov 22, 2017 Nov 22, 2017

Or, in other words:

var a = [30,45,60,15,15,30,30], cols = myTable.columns;

for( var i=cols.length ; i-- ; isNaN(a)||(cols.width=a) );

@+

Marc

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
LEGEND ,
Nov 23, 2017 Nov 23, 2017

Hi Marc,

More readable for me, is this code equivalent to yours?

var myTable = app.selection[0].parent.parent,

a = [10,40,60,15,5,30,10], cols = myTable.columns, C = cols.length, c;

for ( c = 0; c < C; c++ ) if (c < a.length) cols.width = a;

(^/)

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
New Here ,
Dec 04, 2017 Dec 04, 2017

Please can someone help me as I am pretty new to scripting. I have a table with 22.5mm, 15.75mm, 209.25 and 22.5mm through a 20 page document but need to adjust only the first column of 22.5mm to 18mm.

please help with a script. I do not have any table styles set up for this. Ta.

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 Beginner ,
Feb 14, 2021 Feb 14, 2021

Thanks for this info! I've used an adjusted script for indesign 2019 - addition of [i] to denote which column needs to be changed

 

for(var i = 0; i< myTable.columns.length; i++){
if(i==0){
myTable.columns[i].width = 28;
}
else if(i==1){
myTable.columns[i].width = 36;
}
else if(i==2){
myTable.columns[i].width = 27;
}
}

(of course this could be simplified further...

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 ,
May 03, 2021 May 03, 2021
LATEST

Hi Jonathan,

also look into a script by Gerald Singelmann:

Auto Column

https://github.com/gsingelmann/indd_autocolumn

 

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