Highlighted

Help me finish my script to format a cell in a table header?

Participant ,
Oct 29, 2020

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";
    }   
}

 

Adobe Community Professional
Correct answer by Sunil Yadav | Adobe Community Professional

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

TOPICS
Scripting

Views

57

Likes

Translate

Translate

Report

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

Help me finish my script to format a cell in a table header?

Participant ,
Oct 29, 2020

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";
    }   
}

 

Adobe Community Professional
Correct answer by Sunil Yadav | Adobe Community Professional

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

TOPICS
Scripting

Views

58

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Oct 29, 2020 0
Participant ,
Oct 29, 2020

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 29, 2020 0
Adobe Community Professional ,
Oct 29, 2020

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 29, 2020 0
Awitmer LATEST
Participant ,
Oct 30, 2020

Copy link to clipboard

Copied

Thank you very much! This helps me out!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 30, 2020 0