Copy link to clipboard
Copied
Hello!
I am writing a script and need a bit of help to get it finished.
I want the script to go through a whole document and look in the last cell in all the header rows for all the tables in the document and look for the specified text. If it finds the text, I want it to apply a cell style. If it doesn't find the text I am looking for, I want it to simply ignore that cell and table. Does that make sense?
Any help would be appreciated!
Thanks!
if(app.documents.length == 0){
alert("There are no documents open.");
exit();
}
var myDoc = app.activeDocument;
var myTables = myDoc.stories.everyItem().tables.everyItem();
var myRows = myTables.rows.firstItem();
var myCells = myRows.cells.lastItem();
for(var i = 0; i < myDoc.stories.everyItem().tables.length; i++)
{
if (myCells.contents[i] == "Price") {
myCells.appliedCellStyle = "Cell Style 1";
}
if (myCells.contents[i] == "Qty") {
myCells.appliedCellStyle = "Cell Style 1";
}
}
Try this snippet for your reference:
if(app.documents.length == 0){
alert("There are no documents open.");
exit();
}
var myDoc = app.activeDocument;
for(var s = 0; s < myDoc.stories.length; s++){
for(var t = 0; t < myDoc.stories[s].tables.length; t++){
var tempTable = myDoc.stories[s].tables[t];
if(tempTable.rows[0].rowType.toString() == "HEADER_ROW"){
if(tempTable.rows[0].cells[-1].contents == "Price"){
tempTable.rows[0].cells[-1].appl
...
Copy link to clipboard
Copied
I forgot to mention that the problem I am having with this script so far is that it is applying the cell style to all of the cells and not just ones that I have the text I am searching for. That's not what I want.
Copy link to clipboard
Copied
Try this snippet for your reference:
if(app.documents.length == 0){
alert("There are no documents open.");
exit();
}
var myDoc = app.activeDocument;
for(var s = 0; s < myDoc.stories.length; s++){
for(var t = 0; t < myDoc.stories[s].tables.length; t++){
var tempTable = myDoc.stories[s].tables[t];
if(tempTable.rows[0].rowType.toString() == "HEADER_ROW"){
if(tempTable.rows[0].cells[-1].contents == "Price"){
tempTable.rows[0].cells[-1].appliedCellStyle = "Cell Style 1";
}
else if(tempTable.rows[0].cells[-1].contents == "Qty"){
tempTable.rows[0].cells[-1].appliedCellStyle = "Cell Style 1";
}
}
}
}
Best
Sunil
Copy link to clipboard
Copied
Thank you very much! This helps me out!