script to adjust the width of column

Explorer ,
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

1.8K

Likes

translate

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

Adobe Community Professional , 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;          }   ...

Likes

translate

Translate

Translate
Adobe Community Professional ,
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

Likes

translate

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

Likes

translate

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 Community Professional ,
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;

          }

     }

Likes

translate

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

Likes

translate

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;

(^/)

Likes

translate

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.

Likes

translate

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

Likes

translate

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