Script to find & replace cell style of a specific cell
Hello lovely InDesign friends,
I have a problem finding the right direction for my script we would use for all new catalogues in the future.
Starting scenario:
1. We have many tables with tiny information.
2. One cell of each table has a main color provided in a cell style (Name: Green)
3. We need to change the cell style of these cells very easy along 100+ pages to another cell style (Name: Yellow)
4. The paragraph style has to be changed too (black / yellow) -> "Paragraph A" to "Paragraph B" when the cell is changed to . the "Yellow" cell style
I struggle so much getting all cells with the "Green" to "Yellow" cell style and had no success ...
Step 4 is out of my eyes at the moment 😉
Starting situation:

Target situation:

Does anyone have a simple script to change the cell style of every cell using a cell style "XY" to cell style "AB".
var myDoc = app.activeDocument;
// Search for text with 6 digits, e.g. 137335
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "^\d{6}$";
var myFound = myDoc.findGrep();
// Loop for every cell found with myFound
for (i = 0; i < myFound.length; i++) {
// Check if the element is a cell
if (myFound[i].parent.constructor.name == "Cell") {
// Change the cell style to Yellow
myFound[i].parent.appliedCellStyle = "Yellow";
// Overrides changed styles
var overrides = myFound[i].clearOverrides();
}
}
I tried to get the if statement working to check also for appliedCellStyle …
// ...
if (myFound[i].parent.constructor.name == "Cell"; && myFound[i].parent.appliedCellStyle == "Green";) {
// ...- Because the RegEx pattern isn't used by app.findGrepPreferences.findWhat = "^\d{6}$"; I tested everything with a fixed string like "137335". Would be cool if you can give me a hint on that too 😉
I hope everything was written clearly understandable 🙂
Thank you for your feedback anyways!
Greetings
