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

how to define if (myCells[n].appliedCellStyle = xxxx)?

Contributor ,
Aug 09, 2019 Aug 09, 2019

Hi experts,

my script like this:

var docs = app.documents;

    for (var i = docs.length-1; i >= 0; i--) {

            var myCells = docs.stories.everyItem().tables.everyItem().cells.everyItem().getElements(); 

            for(var n = 0; n < myCells.length; n++) 

            { 

                var mCellStyles = docs.allCellStyles;

                for ( var k = 0; k < mCellStyles.length; k++) {

                    myCellstyle = mCellStyles.name.match(/^99|8|7|6/);

                    if (myCells.appliedCellStyle = myCellstyle) {  

                          myCells.contents = " "  

                        }

                    }

                } 

            }

aim to let if the cell which applied cell styles name.match 99 98 97 96

the contents = " "

but it seems not working,

could someone please tell me how to fix it.

thanks

regard

John

TOPICS
Scripting
821
Translate
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 , Aug 09, 2019 Aug 09, 2019

The regular expression is wrong. It should be /^9[9876]/. And using match() for a simple test is expensive because JS tries to create an array. test() is better, it returns true or false. This should work, and is quicker:

for (var n = 0; n < myCells.length; n++) {

  if (/^9[9876]/.test (myCells.appliedCellStyle.name)) {

    myCells.contents = " ";

  }

}

P.

Translate
Community Expert ,
Aug 09, 2019 Aug 09, 2019

Hi John,

= will assign a cell style.

== means is equal to the cell style.

Regards,
Uwe

Translate
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
Community Expert ,
Aug 09, 2019 Aug 09, 2019

As was already noted in the previous how define if (myCells.fillColor = "Black")

Translate
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
Contributor ,
Aug 09, 2019 Aug 09, 2019

thank you guys,

I change this like to:

if (myCells.appliedCellStyle == myCellstyle)

but still not working,

could you please tell me how to fix it?

thanks

regard

John

Translate
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
Advocate ,
Aug 09, 2019 Aug 09, 2019

Hi Johnwhite​,

Try this:

var docs = app.documents; 

for (var i = docs.length-1; i >= 0; i--) { 

    var myCells = docs.stories.everyItem().tables.everyItem().cells.everyItem().getElements();   

    for(var n = 0; n < myCells.length; n++){

        var mCellStyles = myCells.appliedCellStyle;

        var myCellstyle = mCellStyles.name.match(/^99|8|7|6/);

        if (myCellstyle != null){

              myCells.contents = " ";

            }

        }

    }

Best

Sunil

Translate
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
Community Expert ,
Aug 09, 2019 Aug 09, 2019

The regular expression is wrong. It should be /^9[9876]/. And using match() for a simple test is expensive because JS tries to create an array. test() is better, it returns true or false. This should work, and is quicker:

for (var n = 0; n < myCells.length; n++) {

  if (/^9[9876]/.test (myCells.appliedCellStyle.name)) {

    myCells.contents = " ";

  }

}

P.

Translate
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
Contributor ,
Aug 09, 2019 Aug 09, 2019
LATEST

thank you Peter,

thank so much.

John

Translate
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