Skip to main content
July 31, 2013
Question

How can I add a character globally to empty cells in an InDesign table?

  • July 31, 2013
  • 1 reply
  • 1141 views

I have a document with 190 tables, each with many empty cells. Client now wants m-dashes in the empty cells. Is it possible to do this in an automated fashion, without having to go cell-by-cell?

This topic has been closed for replies.

1 reply

Participating Frequently
August 1, 2013

try below code

var myDoc = app.activeDocument;

myPage =myDoc.pages;

for (var p=0; myPage.length>p; p++){

    try{

var myTable =myPage

.textFrames.everyItem().tables.everyItem();

if (myTable.constructor.name == 'Table'){

for (var t=0; myTable.cells.length>t; t++)

            {

           if (myTable.cells.contents==""){

               myTable.cells.contents ="—"

               }

            }

        }

    }

  catch(e){}

}

BEGINNER_X
Legend
August 1, 2013

Hi Kurt,

Please use the below coding also. May it also be helpful for you.

I get an idea from the Mac_rk coding only. Thanks Mac_rk

Coding is below:

try

{

var myCells = app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().getElements();

alert("myCells:" + myCells.length)

for(i=0; i<myCells.length; i++)

{

    if(myCells.contents == "")

    {

        myCells.contents = "—"

        }

    }

}

catch(myError)

{

    alert("no tables found in the active document")

    }

Thanks

Beginner

Known Participant
October 29, 2014

Hi, the last bit of code worked for me, but I was wondering how to get this to only affect the selected table?

Thanks

-Andy