Skip to main content
Participating Frequently
May 13, 2015
Answered

Delete entire column (of a table) if you have specific word

  • May 13, 2015
  • 3 replies
  • 633 views

Can anybody help me?

I have a large document with a lot of tables.

The tables always have the same structure :

a row with the title, and under various columns, where the latter is a price list .

The first word of this last column is PRICE, and what we need is that all cells (with contents ) that are below this cell to be eliminated PRICE ...

I tried to do it with this: https://forums.adobe.com/thread/1533114?q=delete%20rows

but first deleting all PRICE words, but with this script are deleted the rows, not the columns...

Can anybody help me?

Thanks in advance!

This topic has been closed for replies.
Correct answer Sajeev Sridharan

Try this,

var doc = app.activeDocument,  

_cells = doc.stories.everyItem().tables.everyItem().cells.everyItem().getElements();  

 

for ( var k = _cells.length-1; k>= 0; k-- ) { 

    try{ 

         if ( _cells.contents == "PRICE" )  _cells.columns[0].remove(); 

    }catch(e){}; 

    }

3 replies

redobsAuthor
Participating Frequently
May 14, 2015

I tried your script but nothing happens.

I don-t know what i-m doing wrong.

Sorry.

redobsAuthor
Participating Frequently
May 14, 2015

This works fine! but not in my doc...

Itried it in a new doc and works perfect, but in my table doesn't detect the word "PRICE"

It seems that in the cells there are something more. When I copy the word inside cell and go to find and replace it appears as: ^IPRICE But cannot replace...

Thanks for All!

redobsAuthor
Participating Frequently
May 14, 2015

It doesn't work

Legend
May 14, 2015

Can you post a table for review?

redobsAuthor
Participating Frequently
May 14, 2015

Sajeev SridharanCorrect answer
Legend
May 14, 2015

Try this,

var doc = app.activeDocument,  

_cells = doc.stories.everyItem().tables.everyItem().cells.everyItem().getElements();  

 

for ( var k = _cells.length-1; k>= 0; k-- ) { 

    try{ 

         if ( _cells.contents == "PRICE" )  _cells.columns[0].remove(); 

    }catch(e){}; 

    }