Help improving script
Copy link to clipboard
Copied
I have this script. I need that the cell data changes to white when the cell is red, otherwise stay black. If the cell doesn't have any data the cell background should be black 20%. Hope someone can help me!
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Conditional cell formatting");
function main() {
sel = app.selection[0];
var cells = sel.cells
// create color swatches
var red = swatchCreator("Red Cell", [210,35,42]);
var yellow = swatchCreator("Amber", [0,51,99,0]);
var green = swatchCreator("Green", [69,8,87,0]);
for (var c = 0; c < cells.length; c++) {
var cc = cells[c].texts[0].contents.split("%")
var cellValue = parseInt(cc[0])
isNaN(cellValue) && cellValue = 0
if (cellValue < 80) {
cells[c].fillColor = red;
cells[c].texts[0].fillColor = "Paper";
continue;
}
if (cellValue >= 80 && cellValue < 95) {
cells[c].fillColor = yellow;
continue;
}
if (cellValue >= 95) {
cells[c].fillColor = green;
}
}
}
function swatchCreator(colorname, values) {
var swatch = app.activeDocument.colors.item(colorname);
if (!swatch.isValid) {
swatch = app.activeDocument.colors.add({
name: colorname,
model: ColorModel.PROCESS,
space: ColorSpace.CMYK,
colorValue: values
});
}
return swatch;
}
Copy link to clipboard
Copied
Hi @NJR5F92,
The code you posted applies color based on the value of the cell. It doesn't seem to be doing anything that you asked for. Is this the right script that you posted?
-Manan
Copy link to clipboard
Copied
It's an example that OP needs to be altered - but there is a 2nd thread - as mentioned by @Peter Kahrel.
Copy link to clipboard
Copied
This looks the same as https://community.adobe.com/t5/indesign-discussions/help-with-a-script/m-p/14024587
If that's true, please remove this post.
Copy link to clipboard
Copied
Its different. The other code engages when reading percentages on a data cell.
This one changes colours and font colour depending if there is something written in the cell or not.
Copy link to clipboard
Copied
Sure. But it's very much the same idea.

