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

Need to apply table fill color based on text content

Explorer ,
Apr 12, 2013 Apr 12, 2013

Copy link to clipboard

Copied

Totally new to Indesign-scripting – but really need a solution to this:

I have a table

I want to fill the table cell with a different color based on text content.

If cell contents the text "Apple" fill color of cell should be color swatch "Red"

If cell contents the text "Banana" fill color of cell should be color swatch "Yellow"

Any help most appriciated!

TOPICS
Scripting

Views

2.2K

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 ,
Apr 13, 2013 Apr 13, 2013

Copy link to clipboard

Copied

Hi Franke,

Try the below code, may it will helpful:

var myDoc = app.activeDocument

//var myCell = app.activeDocument.textFrames.everyItem().tables.everyItem().cells.everyItem().getElements()

app.findTextPreferences = app.changeTextPreferences = null

app.findTextPreferences.findWhat = "Apple"

var myFound = myDoc.findText()

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

{

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

    {

    myFound.parent.fillColor = "aaa"

    }

}

If the above code helps you, then please give Helpful or Correct Answers.

Because for the last 3 months only I started my Indesign Scripting Career.

With the help of Forum legends I can able to reply for simple questions.

Thanks all...

Regards

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
Explorer ,
Apr 15, 2013 Apr 15, 2013

Copy link to clipboard

Copied

Thanks a lot! Works perfectly.

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 ,
Apr 15, 2013 Apr 15, 2013

Copy link to clipboard

Copied

Hi Frankemans,

Thanks a lot for your reply.

If my script working fine, then please give correct answer for me.

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
Community Expert ,
May 07, 2013 May 07, 2013

Copy link to clipboard

Copied

Someone did one script that apply a selected Cell Style base on GREP find results. Works perfectly even in CS6.

Easy to use even if it is in Japanese!

https://github.com/seuzo/regex_cellstyle

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

Copy link to clipboard

Copied

Do you know how to adjust the japanese script to use without dialogs?

I simply want to apply cellstyle "Yellow" to all cells where the text start with "Banana"?

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

Copy link to clipboard

Copied

LATEST

Hello frankemans,

Rather than adjusting the japanese script you can use BEGINNER_X's script with few changes.

i've modified and the code is below here.

you just need to create the colors in the swatches and to update fruit names and its color

var myDoc = app.activeDocument
app.findGrepPreferences = app.changeGrepPreferences = null
changeColor("Banana",'yellow');     //Copy this line and change name & color for additional...
exit();

function changeColor(Txt2Find,newColor)
{
    app.findGrepPreferences.findWhat = "^"+Txt2Find;
    var myFound=app.findGrep();
    for(i=0; i<myFound.length; i++)
    {
        if(myFound.parent.constructor.name == "Cell")
        {
            myFound.parent.fillColor = myDoc.swatches.item(newColor);
        }
    }
}

hope this helps.

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