Script: conditional formatting of table cells but exclude header row
Hello all,
I've got a script set up to apply a fill color to cells within a table based on the value found within each cell.
It was working fine; however, I just added a piece to it in attempt to have the script exclude the header row. I've already spent hours adapting the original script to my needs, but unfortunately this is where my knowledge, patience, and Google-fu ends.
The error I'm getting is this:
- Error Number: 55
Error String: Object does not support the property or method 'rowType'
Engine: main
File: /Users/c059822/Library/Preferences/Adobe InDesign/Version 14.0/en_US/Scripts/Scripts Panel/stoplight-cell-colors.jsx
Line: 1
Source: app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Conditional cell formatting"); function main()
And here's the script in its current state:
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Conditional cell formatting"); function main()
{
sel = app.selection[0];
if (sel.constructor.name != "TextFrame")
{
alert("Please select the textframe that contains the table.");
exit();
}
// create color swatches
var mint = swatchCreator("First Quartile - Mint", [51,0,32,0]);
var cream = swatchCreator("Second Quartile - Cream", [2,0,45,0]);
var peach = swatchCreator("Third Quartile - Peach", [0,42,36,0]);
var dkred = swatchCreator("Fourth Quartile - Thrivent Dark Red", [0,100,55,23]);
tables = sel.tables;
for (var i = 0; i < tables.length; i++)
{
// ---------Here's the part I added----------
var bodyRows = (tables[i].rows.rowType == RowTypes.BODY_ROW);
for (var r = 0; r < rows.length; r++)
{
// ----------This var used to call on the "for" that looks at the table, above the part I added------------
var cells = bodyRows[r].cells;
for (var c = 0; c < cells.length; c++)
{
var cellValue = parseFloat(cells[c].texts[0].contents);
if (cellValue <= 25)
{
cells[c].fillColor = mint;
continue;
}
if (cellValue >= 26 && cellValue <= 50)
{
cells[c].fillColor = cream;
continue;
}
if (cellValue >= 51 && cellValue <= 75)
{
cells[c].fillColor = peach;
continue;
}
if (cellValue > 76)
{
cells[c].fillColor = dkred;
}
}
}
}
}
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;
}
Any help I can get would be majorly appreciated! Also, I'm new to the forum, so forgive me for any formatting, subject phrasing, etiquette, etc. that is missing here.
