• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Find Text in Table and Apply Cell Style to Entire Row + Cell Style in Group

New Here ,
Jun 26, 2017 Jun 26, 2017

Copy link to clipboard

Copied

Ok, so I have modified the script found here and it is working correctly.

My script:

//Front Subheader

var myDoc = app.activeDocument

//var myCell = app.activeDocument.textFrames.everyItem().tables.everyItem().cells.everyItem().getElement s()

app.findTextPreferences = app.changeTextPreferences = null

app.findTextPreferences.findWhat = "FRONT"

var myFound = myDoc.findText()

for(i=0; i<myFound.length; i++)

{

    if(myFound.parent.constructor.name == "Cell")

    {

    myFound.parent.appliedCellStyle = "SUBHEADER Cell Style"

  var overrides = myFound.clearOverrides()

    }

}

I have two issues however:

1. I want the cell style to apply to the whole row not just the parent cell. I tried changing .parent.constructor.name == "Cell" to .parent.constructor.name == "Row" but that did not work.

2. I want my cell style to be in a group "GENERAL Table Cell Style" and if I put it in there I get an error "46602: A style by that name cannot be found". What would be the separator for the group to the cell style?

Thanks in advance!

TOPICS
Scripting

Views

1.1K

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
community guidelines

correct answers 1 Correct answer

Enthusiast , Jun 26, 2017 Jun 26, 2017

Try this,

var myDoc = app.activeDocument 

app.findTextPreferences = app.changeTextPreferences = null 

 

app.findTextPreferences.findWhat = "FRONT" 

 

var myFound = myDoc.findText() 

 

for(i=0; i<myFound.length; i++) 

        if(myFound.parent.constructor.name == "Cell") 

        { 

                var parentRowCells = myFound.parent.parentRow.cells;

                for(var j=0;j<parentRowCells.length;j++)

                {

                        parentRowCells.appliedCellStyle = myDoc.cellStyleG

...

Votes

Translate

Translate
Enthusiast ,
Jun 26, 2017 Jun 26, 2017

Copy link to clipboard

Copied

Try this,

var myDoc = app.activeDocument 

app.findTextPreferences = app.changeTextPreferences = null 

 

app.findTextPreferences.findWhat = "FRONT" 

 

var myFound = myDoc.findText() 

 

for(i=0; i<myFound.length; i++) 

        if(myFound.parent.constructor.name == "Cell") 

        { 

                var parentRowCells = myFound.parent.parentRow.cells;

                for(var j=0;j<parentRowCells.length;j++)

                {

                        parentRowCells.appliedCellStyle = myDoc.cellStyleGroups.item("GENERAL Table Cell Style").cellStyles.item("SUBHEADER Cell Style");

                   }

               var overrides = myFound.clearOverrides();

            } 

    } 

Regards,

Chinna

Votes

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
community guidelines
New Here ,
Jun 27, 2017 Jun 27, 2017

Copy link to clipboard

Copied

Thanks Chinna that works perfectly.

Is there any way to search for a cell that contains only the word "FRONT" and not cells that contain the word FRONT with other text around it for example FRONT TYRE. At the moment the script is finding these cells too.

Thank you!

Votes

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
community guidelines
Enthusiast ,
Jun 28, 2017 Jun 28, 2017

Copy link to clipboard

Copied

LATEST

Hi,

Pour le Mots seul FRONT,

   app.findGrepPreferences = app.changeGrepPreferences = null   

       

   app.findGrepPreferences.findWhat = "^FRONT$"   

       

    var myFound = myDoc.findGrep() 

A+

Liphou

Votes

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
community guidelines