Skip to main content
Inspiring
November 16, 2025
Answered

Script to select cells of a certain width

  • November 16, 2025
  • 2 replies
  • 78 views

Is it possible to select all cells of a certain width of 130pt and change to a width of 145pt using a script

Correct answer m1b

Hi @Summayah5FC7 here's my approach, similar to @virender_CTS but a little different.

- Mark

 

/**
 * @file Find Change Column Width.js
 * 
 * @author m1b
 * @version 2025-11-17
 * @discussion https://community.adobe.com/t5/indesign-discussions/script-to-select-cells-of-a-certain-width/m-p/15593746
 */
function main() {

    // edit these values to suit your needs
    const FIND_COLUMN_WIDTH = 130; // points
    const CHANGE_COLUMN_WIDTH = 145; // points
    const FIND_THRESHOLD = 0.01;

    app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;

    var doc = app.activeDocument;
    var columns = doc.stories.everyItem().tables.everyItem().columns.everyItem().getElements();
    var counter = 0;

    for (var i = columns.length - 1; i >= 0; i--) {

        var column = columns[i];

        if (Math.abs(column.width - FIND_COLUMN_WIDTH) > FIND_THRESHOLD)
            continue;

        column.width = CHANGE_COLUMN_WIDTH;
        counter++;

    }

    alert('Changed  ' + counter + ' column widths.');

};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Find Change Column Width');

2 replies

m1b
Community Expert
m1bCommunity ExpertCorrect answer
Community Expert
November 16, 2025

Hi @Summayah5FC7 here's my approach, similar to @virender_CTS but a little different.

- Mark

 

/**
 * @file Find Change Column Width.js
 * 
 * @author m1b
 * @version 2025-11-17
 * @discussion https://community.adobe.com/t5/indesign-discussions/script-to-select-cells-of-a-certain-width/m-p/15593746
 */
function main() {

    // edit these values to suit your needs
    const FIND_COLUMN_WIDTH = 130; // points
    const CHANGE_COLUMN_WIDTH = 145; // points
    const FIND_THRESHOLD = 0.01;

    app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;

    var doc = app.activeDocument;
    var columns = doc.stories.everyItem().tables.everyItem().columns.everyItem().getElements();
    var counter = 0;

    for (var i = columns.length - 1; i >= 0; i--) {

        var column = columns[i];

        if (Math.abs(column.width - FIND_COLUMN_WIDTH) > FIND_THRESHOLD)
            continue;

        column.width = CHANGE_COLUMN_WIDTH;
        counter++;

    }

    alert('Changed  ' + counter + ' column widths.');

};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Find Change Column Width');
Inspiring
November 16, 2025

Thanks

Inspiring
November 16, 2025

//~ Is it possible to select all cells of a certain width of 130pt and change to a width of 145pt using a script

var myDoc = app.activeDocument;
myDoc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.POINTS;
myDoc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.POINTS;
var allStories = myDoc.stories;
for(var s = 0; s < allStories.length; s++){
var myStory = allStories[s];
var allTables = myStory.tables;
for(var t = 0; t < allTables.length; t++){
var myTable = allTables[t];
var allCells = myTable.cells;
for(var c = 0; c < allCells.length; c++){
var myCell = allCells[c];
if(myCell.width == 130){
myCell.width = 145;
}
}
}
}

Inspiring
November 16, 2025

Thanks

 

There is an error when executing the script