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!
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
Copy link to clipboard
Copied
Thanks a lot! Works perfectly.
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
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!
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"?
Copy link to clipboard
Copied
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.