Iterating over all of the tables in a document
Hello there. I have a document containing a lot (maybe 100?) similar tables. These tables are used as graphical aids by coloring in certain cells -- rather than the normal use of displaying values. I do not want to manually change each cell color so I wrote a basic script that takes a selected table, looks at the values in one column, and tints the cells in each row accordingly. But now, I don't want to select and run the code for each table manually so I thought I would add a bit extra to simply run the code for every table in the document. It somewhat works (it finds the values in the correct column and it does iterate through the table properly) but instead of only pulling a single cell's value, it pulls multiple values.
For example, if I have two tables and the values to read through in the first table are [1, 3, 1, 2, 2, 1] and are [2, 3, 1, 1, 1, 2] in the second table, I would expect my code to go through the first table and then go through the second table. Instead, it reads '1,2' and then '3,3' etc.
Here is the code: Thank you for your help!
var tablelist = app.documents[0].stories.everyItem().tables;
alert("Edditing "+tablelist.length+" tables in document");
var t;
for (t=0; t<tablelist.length; t++){
var
table = tablelist
, len = table.cells.length,
i;
//alert(table);
//alert(table.cells);
for (i=3; i <= len;) {
var value = table.cells.contents;
alert(table.cells);
if (value == 1){
table.cells[i-1].fillTint = 0;
table.cells[i-2].fillTint = 0;
table.cells[i-3].fillTint = 100;
};
else if (value == 2){
table.cells[i-1].fillTint = 0;
table.cells[i-2].fillTint = 100;
table.cells[i-3].fillTint = 0;
};
else if (value == 3){
table.cells[i-1].fillTint = 100;
table.cells[i-2].fillTint = 0;
table.cells[i-3].fillTint = 0;
};
else {
alert("invalid fill " + value);
table.cells.fillColor = "Black";
};
i += 4;
};
};
