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

How to apply a table cell style based on grep search?

Explorer ,
Jun 17, 2013 Jun 17, 2013

Copy link to clipboard

Copied

Anyone that know how to make a script that searches in an Indesign table for

-> All cells where the text starts with "Banana"

-> And apply cell style "Yellow" to these cells?

I have been searching on forums for somedays and got this tip: https://github.com/seuzo/regex_cellstyle/blob/master/regex_cellstyle.jsx

-> But that script is in japanese and also use dialogs.

All help most appriciated!

TOPICS
Scripting

Views

5.3K

Translate

Translate

Report

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

Enthusiast , Jun 18, 2013 Jun 18, 2013

Hi Frankemans,

var myDoc = app.activeDocument

app.findTextPreferences = app.changeTextPreferences = null

app.findTextPreferences.findWhat = "Banana"

var myFound = myDoc.findText()

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

{

    if(myFound.parent.constructor.name == "Cell")

    {

   myFound.parent.appliedCellStyle = "Yellow"

      var overrides = myFound.clearOverrides()          //this is the new line added in this content

   

    }

}

Thanks

Beginner

Votes

Translate

Translate
Enthusiast ,
Jun 17, 2013 Jun 17, 2013

Copy link to clipboard

Copied

Hi Frankeman,

Please try the below code, may it should be helpful:

var myDoc = app.activeDocument

app.findTextPreferences = app.changeTextPreferences = null

app.findTextPreferences.findWhat = "Banana"

var myFound = myDoc.findText()

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

{

    if(myFound.parent.constructor.name == "Cell")

    {

   

   myFound.parent.appliedCellStyle = "Yellow"

    }

}

Suppose the code is working fine for you, then please click correct answers.

thanks

Beginner_X

Votes

Translate

Translate

Report

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 18, 2013 Jun 18, 2013

Copy link to clipboard

Copied

Almost there!

The script applies the correct cell style but with overrides.

-> See attached file.

-> Any way to make a script that clears all overrides?

OVERRIDES.png

Votes

Translate

Translate

Report

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
Enthusiast ,
Jun 18, 2013 Jun 18, 2013

Copy link to clipboard

Copied

Hi Frankemans,

var myDoc = app.activeDocument

app.findTextPreferences = app.changeTextPreferences = null

app.findTextPreferences.findWhat = "Banana"

var myFound = myDoc.findText()

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

{

    if(myFound.parent.constructor.name == "Cell")

    {

   myFound.parent.appliedCellStyle = "Yellow"

      var overrides = myFound.clearOverrides()          //this is the new line added in this content

   

    }

}

Thanks

Beginner

Votes

Translate

Translate

Report

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
New Here ,
Sep 09, 2015 Sep 09, 2015

Copy link to clipboard

Copied

Hi guys I'm looking for something like this. I've found and used executable scripts before, but have never 'programmed one' and put it into InDesign using code like the one above. i'm using CS5.5 on a windows machine. Could anyone let me know what to do or point me in the direction of a post explaining? many thanks

Grebe

Votes

Translate

Translate

Report

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
New Here ,
Jul 08, 2019 Jul 08, 2019

Copy link to clipboard

Copied

Hi,

Am I able to add multiple if/else statements in this script?

Asking as I need to shade table cells based on the value within them.

Such as I need a 1 to be light blue, 2 to be a bit darker, 3 a little darker, and so on.

Many, many thanks in advance.

Votes

Translate

Translate

Report

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 ,
Feb 03, 2020 Feb 03, 2020

Copy link to clipboard

Copied

Hi!

I have a problem with this script : every time I try to run it, InDesign CC 2020 tells me that there is an error. It says :

error 21

undefined is not an object

Line : 13

Source :  if(myFound.parent.constructor.name == "Cell")

 

Is there something I missed? I thought I just had to replace Banana and Yellow by whatever I wanted and that's all...

If this problem is solved, I have another question : can I use one and only script to apply different formats to other cells containing specific cells? (For example I want all the "2018" and "2019" cells in blue, all the "Investissements" and "Concessions" cells in green).

Thank you very much

Ecureuil

Votes

Translate

Translate

Report

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 ,
Feb 03, 2020 Feb 03, 2020

Copy link to clipboard

Copied

...Has the fact that InDesign is in french in my computer anything to do with this?

Thanks a lot

Ecureuil

Votes

Translate

Translate

Report

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
Community Expert ,
Feb 03, 2020 Feb 03, 2020

Copy link to clipboard

Copied

No. The restored code I posted should run in any language version of InDesign.

 

As I already said: The code was damaged by transferring this old thread from the Jive-based old forum to this new one. Definitely not your fault.

 

Regards,
Uwe Laubender

( ACP )

Votes

Translate

Translate

Report

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
Community Expert ,
Feb 03, 2020 Feb 03, 2020

Copy link to clipboard

Copied

Hi Ecureuil,

the problem indeed lies in the posted code.

This code was damaged when the thread was transferred to the new InDesign forum last year.

Inside the for-loop iterator i is missing.

 

Here the restored code:

var myDoc = app.activeDocument ;
app.findTextPreferences = app.changeTextPreferences = null ;
app.findTextPreferences.findWhat = "Banana" ;

var myFound = myDoc.findText() ;

for( var i=0; i<myFound.length; i++)
{
    if( myFound[i].parent.constructor.name == "Cell" )
    {
		myFound[i].parent.appliedCellStyle = "Yellow";
		var overrides = myFound[i].clearOverrides();       //this is the new line added in this content
    };
};

 

Also note:

The original is from 2013 and may have worked for InDesign CS6.

I did not test it

 

Regards,
Uwe Laubender

( ACP )

Votes

Translate

Translate

Report

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
Community Expert ,
Feb 03, 2020 Feb 03, 2020

Copy link to clipboard

Copied

Just another annotation:
The code is NOT using a GREP search. It's just a plain TEXT search.

 

Regards,
Uwe Laubender

( ACP )

 

 

Votes

Translate

Translate

Report

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 ,
Feb 03, 2020 Feb 03, 2020

Copy link to clipboard

Copied

LATEST

It works on Design CC 2020! Thanks a lot!

Note : In the Cell styles pannel, if the cell style ("yellow") is in a group of styles, the script doesn't find it. I guess it is logical but it is good to remember that :).

 

Yes, I have seen there was a difference between Text and GREP, but thanks for reminding me about it, it is really easy to confuse the two of them ^^.

Since your reply, I also have tested he GREP research (thanks to another post), which worked pretty well after changing some lines. I used it to search several words at the same time, it is very effective too.

 

Can I ask you another question?

I would like to :

- format the "pear" cells in green

- format the "prune or cherry or blueberries" cells in violet

- format the "apple" cells in red.

For now, I created one file for each request, which is maybe not the more convenient thing to do. Is it possible to cumulate them on one single file? I guess it is not very complicated but I am a total newbie in Javascript, I don't know how the code works :}

Best
Ecureuil

 

 

Votes

Translate

Translate

Report

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