Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
5

Help improving script

Community Beginner ,
Aug 21, 2023 Aug 21, 2023

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;

}

 

NJR5F92_0-1692631183677.pngexpand image

 

TOPICS
Scripting
176
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 21, 2023 Aug 21, 2023

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 22, 2023 Aug 22, 2023

It's an example that OP needs to be altered - but there is a 2nd thread - as mentioned by @Peter Kahrel

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 22, 2023 Aug 22, 2023

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 22, 2023 Aug 22, 2023

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 22, 2023 Aug 22, 2023
LATEST

Sure. But it's very much the same idea.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines