Copy link to clipboard
Copied
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
1 Correct answer
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.
Copy link to clipboard
Copied
Hi John,
= will assign a cell style.
== means is equal to the cell style.
Regards,
Uwe
Copy link to clipboard
Copied
As was already noted in the previous how define if (myCells.fillColor = "Black")
Copy link to clipboard
Copied
thank you guys,
I change this like to:
if (myCells
but still not working,
could you please tell me how to fix it?
thanks
regard
John
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
thank you Peter,
thank so much.
John

