Question
Help improving script
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;
}

