Script to search tables in a document and apply cell style based on Column Title
Hello,
I'm trying to get a script for applying cell styles based on content. Since I'm really new to scripting I can't get this to work as I want to. I have a script that will find a number and change the cell style based on the number, but I need to use a second formula for finding the cell to apply the cell style to, based on the Column Title.
So for example I have four columns that are "ranks," and those would just have red, yellow, or green backgrounds applied (which I change with a cell style)(e.g. 0-49.99, 50.00-69.99, 70.00-100). But then I have four columns that are "grades," and they have more variety in the colors (red, orange, yellow, green, blue; e.g. 0-24.99, 25.0-44.99, 45.0-59.99, 60.0-79.99, 80.0-100).
The following script does what I want for the first situation, but it then I can't run the second script because it will change the colors I already changed using the first script. Is there a way to search by column title and apply the formula, so I don't have to go through and manually select each text frame to apply the second forumula? Does that make sense?
Can anyone help me with this?
var myDoc = app.activeDocument ;
var myFrame = app.selection[0];
if(app.selection <1){
alert ("Please select a table or a frame containing a table.");
}
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "^[6-7]\\d+(\\.\\d+)?";
var myFound = myFrame.findGrep();
for( var i=0; i<myFound.length; i++)
{
if( myFound[i].parent.constructor.name == "Cell" )
{
myFound[i].parent.appliedCellStyle = "Grade Yellow";
var overrides = myFound[i].clearOverrides(); //this is the new line added in this content
};
};
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "^[8]\\d+(\\.\\d+)?";
var myFound = myFrame.findGrep();
for( var i=0; i<myFound.length; i++)
{
if( myFound[i].parent.constructor.name == "Cell" )
{
myFound[i].parent.appliedCellStyle = "Grade Green";
var overrides = myFound[i].clearOverrides(); //this is the new line added in this content
};
};
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "^[9]\\d+(\\.\\d+)?";
var myFound = myFrame.findGrep();
for( var i=0; i<myFound.length; i++)
{
if( myFound[i].parent.constructor.name == "Cell" )
{
myFound[i].parent.appliedCellStyle = "Grade Blue";
var overrides = myFound[i].clearOverrides(); //this is the new line added in this content
};
};

