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

Script to find a cell style or paragraph style and change cell style according to cell content

Explorer ,
Apr 22, 2020 Apr 22, 2020

Copy link to clipboard

Copied

I have a table with several columns of numbers. Some numbers need to have just a gray background.

 

Others need to have a colored background depending on the number. Using a decimal search allows me to differentiate those numbers from whole integers. But there is a final column that has different conditional formatting... a larger range of colors to be applied to numbers.

 

On this particular table, because it is a data merge and I don't want to repeat the headers over and over on the page, I have eliminated the Table Header Row other than on the master page, so now I don't have a way to differentiate that column (I had been applying the cell style based on each header, which worked great).

 

I can apply a cell style or a paragraph style to the content in the cell to disctinguish it from the other numbers, but I don't know how to *both* search for a cell or paragraph style *and* then still search for the range of numbers to apply the various colors. Does that make sense?

 

So I have

******

// All the tables in the active document! …
var myCells = app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().getElements(),
C = myCells.length, c;


for ( c = 0; c < C; c++ ) {

if ( myCells[c].columns[0].cells[0].texts[0].contents.match(/\d\.\d/) && myCells[c].contents != "" ) {
if ( Number(myCells[c].contents) >= 0 && Number(myCells[c].contents) < 59.99 ) myCells[c].appliedCellStyle = "Grade Red";
if ( Number(myCells[c].contents) >= 60 && Number(myCells[c].contents) < 69.99 ) myCells[c].appliedCellStyle = "Grade Orange";
if ( Number(myCells[c].contents) >= 70 && Number(myCells[c].contents) < 79.99 ) myCells[c].appliedCellStyle = "Grade Yellow";
if ( Number(myCells[c].contents) >= 80 && Number(myCells[c].contents) < 89.99 ) myCells[c].appliedCellStyle = "Grade Green";
if ( Number(myCells[c].contents) >= 90 && Number(myCells[c].contents) <= 100 ) myCells[c].appliedCellStyle = "Grade Blue";
}

}
******

but for that first search

if ( myCells[c].columns[0].cells[0].texts[0].contents.match(/\d\.\d/) && myCells[c].contents != "" ){

 

I need it to also either search for Cell Style "Points Gray" or Paragraph Style "Points" but I can't figure out how to do that.

TOPICS
Scripting

Views

854

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

Community Expert , Apr 22, 2020 Apr 22, 2020

How about 

if ( myCells[c].columns[0].cells[0].texts[0].contents.match(/\d\.\d/) && myCells[c].contents != "" && (myCells[c].texts[0].appliedParagraphStyle.name == "Points" || myCells[c].appliedCellStyle.name = "Points Gray"))

-Manan 

Votes

Translate

Translate
Community Expert ,
Apr 22, 2020 Apr 22, 2020

Copy link to clipboard

Copied

LATEST

How about 

if ( myCells[c].columns[0].cells[0].texts[0].contents.match(/\d\.\d/) && myCells[c].contents != "" && (myCells[c].texts[0].appliedParagraphStyle.name == "Points" || myCells[c].appliedCellStyle.name = "Points Gray"))

-Manan 

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