Debug Script: Set Column Size; Add Table Border

Home Forums InDesign Add-ons (Scripts, Scripting, and Plug-ins) Debug Script: Set Column Size; Add Table Border

This topic contains 4 replies, has 2 voices, and was last updated by  Heidi Quellet 2 months, 3 weeks ago.

  • Author
  • #104282

    De Jong’s script is helping me to format tables placed/linked from Excel. Using ExtendScript Tool Kit; Mac OS, Indesign CC 2018, beginner coder, ref: I purchased Smart Styles but I still need a script to set column width.

    1) Reformatting a large catalog. Table on each page, 9 columns. Script works except to format columns 8-9. Fails on line 74. Error Number 45; object invalid. Source: myTables(t)columns[8].width = “11mm”; (see below).

    2) I place a spreadsheet as an Unformatted Table with Table Style: Table-Setup > Table Border = 2pt solid grey. It does not show up. There must be a cell/paragraph style overriding it. Should I use script instead? It would start on row 3 (the body) and stop before footer row.

    3) Table Style sets up alternating grey/white fill, skipping first 2 rows and last 1 row. It works; should I use scripting instead? AlternatingFillsTypes.ALTERNATING_ROWS.

    app.doScript(checkUserSelection, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, “Process Table”);

    function checkWhichTable()
    // ensure the user made a selection
    if (app.selection.length != 1)
    return null;
    var currentTable = app.selection[0];
    if (currentTable.hasOwnProperty(“baseline”))
    currentTable = app.selection[0].parent;
    while (currentTable instanceof Cell || currentTable instanceof Row || currentTable instanceof Column)
    currentTable = currentTable.parent;
    if (!(currentTable instanceof Table))
    // No table selected
    return null;
    return currentTable;

    function checkUserSelection ()
    var a_table = checkWhichTable();
    if (a_table == null)
    if (confirm(“No table selected. Do you want to process *all* tables?”) == false)
    allTables = app.activeDocument.stories.everyItem().tables.everyItem().getElements();
    for (aTable=0; aTable<allTables.length; aTable++)
    processTable (allTables[aTable]);
    } else
    processTable (a_table);

    function processTable(table)
    // do something here!
    table.rows[0].fillColor = “Symbiote Blue”;
    table.rows[1].fillColor = “Symbiote Blue”;
    table.rows.everyItem().height = “12pt”;

    var myDoc = app.activeDocument
    app.findTextPreferences = app.changeTextPreferences = null
    app.findTextPreferences.findWhat = “Rev”
    var myFound = myDoc.findText()
    for(i=0; i<myFound.length; i++)
    if(myFound[i] == “Cell”)
    myFound[i].parent.appliedCellStyle = “cell-footer-row-grey”
    var overrides = myFound[i].clearOverrides()

    var myDoc = app.activeDocument;
    var myTables = myDoc.stories.everyItem().tables.everyItem().getElements();

    for ( var t = 0; t < myTables.length; t++ ) {
    if ( myTables[t] == “Spreadsheet-Import” ) {
    myTables[t].columns[0].width = “25mm”;
    myTables[t].columns[1].width = “70mm”;
    myTables[t].columns[2].width = “10mm”;
    myTables[t].columns[3].width = “12mm”;
    myTables[t].columns[4].width = “12mm”;
    myTables[t].columns[5].width = “11mm”;
    myTables[t].columns[6].width = “12mm”;
    myTables[t].columns[7].width = “11mm”;
    myTables[t].columns[8].width = “11mm”;


  • #104314

    Heidi, it is helpful, if you provide a example, where we can see the error too. Otherwise it is difficult to give you a tip here.

  • #104945

    Folder link – contains the script file and InDesign file with table (see page 3). Thanks!

  • #105029

    Heidi, there is no table style “Spreadsheet-Import” applied in your document. SIP DIMS TABLE doesn’t produce any error ??

  • #105079

    Thanks for looking at the script. The original script called the table style “Spreadsheet-Import”. The new script calls table style “SIP DIMS TABLE” and is working correctly now – as a standalone script. I tried to incorporate this code into a larger script and got errors. But, the longer script (above) is no longer needed. I purchased Wood Wing Smart Styles to format the table shading, borders and row height. It’s a very helpful plug-in.

You must be logged in to reply to this topic.