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

script to adjust the width of column

Participant ,
Sep 12, 2017 Sep 12, 2017

Copy link to clipboard

Copied

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

Views

4.2K

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

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;

          }

   

...

Votes

Translate

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

moved to InDesign Scripting

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

Copy link to clipboard

Copied

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;

          }

     }

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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;

(^/)

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

Copy link to clipboard

Copied

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.

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

Copy link to clipboard

Copied

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...

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

Copy link to clipboard

Copied

LATEST

Hi Jonathan,

also look into a script by Gerald Singelmann:

Auto Column

https://github.com/gsingelmann/indd_autocolumn

 

Regards,
Uwe Laubender

( ACP )

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