Debug Script: Set Column Size; Add Table Border
Learn / Forums / InDesign Add-ons (Scripts, Scripting, and Plug-ins) / Debug Script: Set Column Size; Add Table Border
Tagged: Scripting, table styles
- This topic has 5 replies, 3 voices, and was last updated 4 years, 4 months ago by Monisha Rajendran.
-
AuthorPosts
-
-
June 11, 2018 at 12:57 pm #104282Heidi QuelletMember
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”;
}
}}
-
June 14, 2018 at 1:13 pm #104314Kai RübsamenMember
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.
-
July 18, 2018 at 8:00 am #104945Heidi QuelletMember
Folder link – contains the script file and InDesign file with table (see page 3). Thanks!
https://www.dropbox.com/sh/m1rtl9596qgxl3s/AABbt779W5ahpjVG03ujgWi4a?dl=0
-
July 20, 2018 at 1:25 am #105029Kai RübsamenMember
Heidi, there is no table style “Spreadsheet-Import” applied in your document. SIP DIMS TABLE doesn’t produce any error ??
-
July 23, 2018 at 7:09 am #105079Heidi QuelletMember
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.
-
November 18, 2019 at 11:10 pm #14323683Monisha RajendranMember
how to assign the hyperlink for one attribute to another attribute using jsx. For example code_link attribute has an hyper link while pressing the code attribute value it want to move to the link site. What i want to do in code.
-
-
AuthorPosts
- You must be logged in to reply to this topic.