Copy link to clipboard
Copied
Is there any possibility to set a paragraph style to certain cells based on another cell value in another column? Or instead of setting a paragraph style just change the text color.
Example what I am looking for (see screenshot):
I want the color of the text in column "D" to change based on the cell value in column "C". All the texts written by John should be green and all texts written by David should be red.
A script would make sense as I have thousands of rows. Any ideas?
 
[ attachment inserted as inline image by moderator ]
Certainly doable with a script. You can look at this thread for inspiration.
Here is a non-script workaround with a little finagling:
First, column D will be replaced with a merged column of C and D. The reason to do this merge is to create an indicator, the indicator can be David and John, or D and J, or some specific indicator.
Replace column
Create 3 character styles: blank, red, green
Create a paragraph grep style with the following:
Note: This is one paragraph style that will change copy based on the indicators of D and J. You would change the character style of bl
...Dirtly and simplistically done, just calling your para styles "John" and "David"! … 😉
/*
_FRIdNGE-0685_ApplyParaStyleToNextCell.jsx
Script written by FRIdNGE, Michel Allio [08/12/2020]
*/
var myNames = ["John", "David"];
for ( var n = 0; n < myNames.length ; n++ ) {
app.findGrepPreferences = null;
app.findGrepPreferences.findWhat = "^" + myNames[n] + "$";
myFound = app.activeDocument.findGrep();
for ( var f = 0; f < myFound.length ; f++ ) if ( myFound[f].parent instan
...
Copy link to clipboard
Copied
Certainly doable with a script. You can look at this thread for inspiration.
Copy link to clipboard
Copied
Here is a non-script workaround with a little finagling:
First, column D will be replaced with a merged column of C and D. The reason to do this merge is to create an indicator, the indicator can be David and John, or D and J, or some specific indicator.
Replace column
Create 3 character styles: blank, red, green
Create a paragraph grep style with the following:
Note: This is one paragraph style that will change copy based on the indicators of D and J. You would change the character style of blank to 0 pt to make it invisible.
Copy link to clipboard
Copied
Dirtly and simplistically done, just calling your para styles "John" and "David"! … 😉
/*
_FRIdNGE-0685_ApplyParaStyleToNextCell.jsx
Script written by FRIdNGE, Michel Allio [08/12/2020]
*/
var myNames = ["John", "David"];
for ( var n = 0; n < myNames.length ; n++ ) {
app.findGrepPreferences = null;
app.findGrepPreferences.findWhat = "^" + myNames[n] + "$";
myFound = app.activeDocument.findGrep();
for ( var f = 0; f < myFound.length ; f++ ) if ( myFound[f].parent instanceof Cell ) if ( myFound[f].parent.parent.cells[myFound[f].parent.index+1] && myFound[f].parent.parentRow == myFound[f].parent.parent.cells[myFound[f].parent.index+1].parentRow ) myFound[f].parent.parent.cells[myFound[f].parent.index+1].texts[0].appliedParagraphStyle = myNames[n];
}
(^/) The Jedi