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
1 Correct answer
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;
}
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.
Copy link to clipboard
Copied
moved to InDesign Scripting​
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;
}
}
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
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 ;
(^/)
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.
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...
Copy link to clipboard
Copied
Hi Jonathan,
also look into a script by Gerald Singelmann:
Auto Column
https://github.com/gsingelmann/indd_autocolumn
Regards,
Uwe Laubender
( ACP )

