Skip to main content
March 12, 2013
Answered

Is there a way to add text to cells and apply character style in cell

  • March 12, 2013
  • 1 reply
  • 624 views

I'm working in InDesign 5 on a Mac.

I'm formating two tables with info that will eventually be combined. I've put together   scripts  I found on these forums to add the necessary columns, merge rows and fill the merged cells with the correct color, but am having trouble with two remaining tasks.

1. Is it possible to add text to a certain cell?

2. And is it possible to apply a character style to certain cells? (different cells than the ones I need to add text)

I've been playing with this code, but don't know if it's even close . . .

{

          table.rows[0].cells[0].insertText ("CS/PS");

}

{

          table.rows[0].cells[0].appliedCharacterStyle ("bold");

}

The following are the scripts I've combined so far for the table. . .

// add column

myTable = app.selection[0];

myColumn = myTable.columns[1];

for (a=0; a < 1; a++)

{

    myTable.columns.add(LocationOptions.AFTER, myColumn);

    }

// merge rows

table = app.selection[0];

if (table.hasOwnProperty("baseline")) table = table.parent;

if (table instanceof Cell) table = table.parent;

if (table instanceof Column) table = table.parent;

if (table instanceof Row) table = table.parent;

if (table instanceof Table)

{

          table.rows[0].cells[0].merge (table.rows[0].cells[1]);

}

{

// alternate colors in merged rows

r = table.rows[1];

n = app.activeDocument.swatches.item("orange");

b = app.activeDocument.swatches.item("PANTONE 3005 C");

for (c=0; c<r.cells.length; c++)

{

  if (c & 1)

  r.cells.properties = { fillColor:b};

  else

  r.cells.fillColor = n;

}

}

This topic has been closed for replies.
Correct answer Jump_Over

Hi,

1. to add the text you have to go deeper into:

     table.rows[0].cells[0].insertionPoints[0].contents =  "CS/PS";

2. similar with applying styles:

     table.rows[0].cells[0].texts[0].appliedCharacterStyle = "bold" // if this style is present in your doc

Jarek

1 reply

Jump_Over
Jump_OverCorrect answer
Legend
March 12, 2013

Hi,

1. to add the text you have to go deeper into:

     table.rows[0].cells[0].insertionPoints[0].contents =  "CS/PS";

2. similar with applying styles:

     table.rows[0].cells[0].texts[0].appliedCharacterStyle = "bold" // if this style is present in your doc

Jarek