-
1. Re: [JS][CS4] - Conditional statements in a table?
Laubender Sep 13, 2011 2:00 PM (in response to booyajamo)Lindsay,
myTable.rows.everyItem().cells.item(-1).contents;
will give you an array which you can loop through.
myTable.columns[-1].contents
gives you the same array.
See the following script:
//a table is selected: var _table = app.selection[0]; //The following checks will be incremented by 1 every time the loop goes through. //If the checks number is equal the number of cells we loop through, //the first column of the table will be filled by a specified color: //Default is 0: var _check3 = 0; var _check4 = 0; //Our array we need to check: var _contentsArray = _table.columns[-1].contents; //regEx matches a certain number followed by 5 arbitrary numbers //the .source-trick is by John Hawkinson; no need for extra escaping backslashes: for(var n=0;n<_contentsArray.length;n++){ if(_contentsArray[n].match(/3\d{5}/.source)){++_check3}; if(_contentsArray[n].match(/4\d{5}/.source)){++_check4}; }; if(_check3 === _contentsArray.length){_table.columns[0].fillColor = "Magenta"}; if(_check4 === _contentsArray.length){_table.columns[0].fillColor = "Blue"};Oh, and btw you can use the following feature of the forum software to highlight your code:
>> Syntax Highlighting > Java
Uwe
-
2. Re: [JS][CS4] - Conditional statements in a table?
booyajamo Sep 22, 2011 1:53 PM (in response to Laubender)Hi Uwe,
Thank you for taking the time to help me! Not sure what I am doing wrong but the script isn't appearing to do anything. It runs without any errors, but the first column does not have color in it and the last column do have numbers in them which should trigger the fill color.
I copied the script you have above and added:
myTable.select();
just prior to all the stuff you have under "see the following script". I figured I needed to add that line so it selected the table - because when I delete it, the script says the var_contentsArray is an undefined object.
The entire table is highlighted when the script is finished if that means anything ??
Any help is greatly appreciated.
Thanks,
Lindsay
-
3. Re: [JS][CS4] - Conditional statements in a table?
Laubender Sep 22, 2011 11:56 PM (in response to booyajamo)Hi, Lindsay!
You can be sure that I tested that script on a table in InDesign CS4.
Maybe this script is oversimplistic.If you added myTable.select() to script without declaring the var myTable you should get an error out of the ESTK.
You have to select a full table at the beginning before running the script from ESTK or InDesign.
To test it yourself I have to send you two IDML files by E-Mail of my test document here together with the script that I ran from the ESTK.
Please send me a private message with your E-Mail address or answer that one I already sent to you.AND all cells in the last column have to match a number beginning with "3" or "4" that is 6 digits long in total.
Uwe
-
4. Re: [JS][CS4] - Conditional statements in a table?
Haakenlid Sep 23, 2011 3:06 AM (in response to Laubender)Lindsay, can you post a screenshot of how you want your table to look like? Your description is a bit ambiguous. Do you want the entire first column to have the same colour, like Laubender's script does, or do you want each cell in the first row to have a different swatch?
-
5. Re: [JS][CS4] - Conditional statements in a table?
frankemans Apr 12, 2013 8:42 AM (in response to Haakenlid)Is there anyway to adjust the script above to search for text content - and if found – apply "Magenta" as a fill color to that cell.
Example
Apple 20
Orange 10
If the cell contains "Apple" the fill color of that cell should be color swatch "Magenta"
Have been searching for a solution to this for weeks – so any help most appriciated ;-)


