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: https://jongware.mit.edu/idcs6js/pc_Table.html. 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)
return;
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].parent.constructor.name == “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].appliedTableStyle.name == “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”;
}
}
}