Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
1

InDesign script to delete table rows containing specific text

Explorer ,
Jun 26, 2018 Jun 26, 2018

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!

TOPICS
Scripting
2.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Jun 26, 2018 Jun 26, 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]

...
Translate
Advocate ,
Jun 26, 2018 Jun 26, 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++;

    }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 26, 2018 Jun 26, 2018

This is perfect, thanks!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Apr 18, 2023 Apr 18, 2023
LATEST

how would I adjust this so it would delete empty rows without any content?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines