Skip to main content
adamg86737138
Inspiring
June 27, 2018
Answered

InDesign script to delete table rows containing specific text

  • June 27, 2018
  • 1 reply
  • 2905 views

Am after a script to search through all table rows of tables in the current document for specific text. In this instance it's "BLANKITYBLANK". Once it finds said text I want it to then delete/remove that entire table row. I have done some thorough searching the forums however can only seem to find scripts relating to empty rows.

I'm sure this is possible just not sure how to go about it.

Thanks in advance!

This topic has been closed for replies.
Correct answer Sunil Yadav

Hi,

     You should try this below code,

var allStories = app.documents[0].stories;

var st = 0;

while(st < allStories.length){

    var allTables = allStories[st].tables;

    var tbl = 0;

    while(tbl < allTables.length){

        var allCells =  allTables[tbl].cells;

        var cel = 0;

        while(cel < allCells.length){

            if(allCells[cel].contents.toString().toLowerCase().indexOf("blankityblank") != -1){

                allCells[cel].rows[0].remove();

                allCells =  allTables[tbl].cells;

                cel = -1;

                }

            cel++;

            }

        tbl++;

        }

    st++;

    }

1 reply

Sunil Yadav
Sunil YadavCorrect answer
Legend
June 27, 2018

Hi,

     You should try this below code,

var allStories = app.documents[0].stories;

var st = 0;

while(st < allStories.length){

    var allTables = allStories[st].tables;

    var tbl = 0;

    while(tbl < allTables.length){

        var allCells =  allTables[tbl].cells;

        var cel = 0;

        while(cel < allCells.length){

            if(allCells[cel].contents.toString().toLowerCase().indexOf("blankityblank") != -1){

                allCells[cel].rows[0].remove();

                allCells =  allTables[tbl].cells;

                cel = -1;

                }

            cel++;

            }

        tbl++;

        }

    st++;

    }

adamg86737138
Inspiring
June 27, 2018

This is perfect, thanks!