Skip to main content
dublove
Legend
July 19, 2025
Answered

How can I tell if the last row has an "ABC" cell style applied?

  • July 19, 2025
  • 1 reply
  • 515 views

It doesn't seem right for me to write it this way.

The result in if is always false.

 

if(table.rows[-1].cells.everyItem().appliedCellStyle.name!=="ABC"){
. . .
}

 

Correct answer rob day

Hi rob day.

table.rows[-1].cells.everyItem().texts.everyItem().pointSize = 0.1;
How this sentence is written inside { } is now incorrect. 

Also, it won't let me just write height: 1.058mm?

 

table.rows[-1].cells.everyItem().properties = {
    appliedCellStyle: "ABC",
    contents: "",
    texts.everyItem().pointSize: 0.1,
    bottomEdgeStrokeWeight: 0,
    leftEdgeStrokeWeight: 0,
    rightEdgeStrokeWeight: 0,

    topInset:0,
    leftInset: 0,
    bottomInset: 0,
    rightInset: 0,
    
    autoGrow: false,
    height: 1.058,
}

 

 


table.rows[-1].cells.everyItem().texts.everyItem().pointSize = 0.1;

 

You would have to set the text properties separately. Also top, left, bottom, and rightInset have been deprecated to textTopInset (ect), And if you don’t want to set ruler or scripting units, use a string like this "1.058 mm":

 

//the first table in the active document
var t1 = app.activeDocument.stories[0].tables[0]
//all the cells in the last row
var lrc = t1.rows[-1].cells.everyItem().getElements();
var b = false
//check each cell of the last row. If any of the applied cell syle names are ABC set b to true
for (var i = 0; i < lrc.length; i++){
    if (lrc[i].appliedCellStyle.name == "ABC") {
        b = true;
    } 
}; 

// make a new row and set every cell style to "ABC"
if (!b) {
	t1.rows.add();
    //set cell properties
    t1.rows[-1].cells.everyItem().properties = { appliedCellStyle: "ABC", height: "1.058 mm", textTopInset: 0}
    //set cell text properties
    t1.rows[-1].cells.everyItem().texts.everyItem().properties = {pointSize: 0.1}
    
} 
alert(b + ": Add Row")

1 reply

rob day
Community Expert
Community Expert
July 19, 2025

Hi @dublove , Your code throws multiple errors—you would need to specify the document’s table and the cell properties. If you want to check the appliedCellStyle of every cell in a row, you’ll need to loop through the row’s cells.

 

If you want to change all of a row’s cells to the same style, something like this would work:

 

//the first table in the active document
var t1 = app.activeDocument.stories[0].tables[0]
t1.rows[-1].cells.everyItem().properties = {appliedCellStyle:"ABC"}
 
But it would throw an error if a cell style named "ABC" did not exist, so you could add a try statement like this:
 
var t1 = app.activeDocument.stories[0].tables[0]
try {
    t1.rows[-1].cells.everyItem().properties = {appliedCellStyle:"ABC"}
}catch(e) {}

 

 

dublove
dubloveAuthor
Legend
July 20, 2025

Hi rob day.

Thank you very much.
I just need

if(table.rows[-1].cells.everyItem().properties != { appliedCellStyle: "ABC" }){
. . . . . .
}

It works.
That's good. Doesn't it look a little weird?
I've seen some people use it like this: appliedCellStyle=="ABC"
I don't know if theirs works either.

rob day
Community Expert
Community Expert
July 20, 2025

I've seen some people use it like this: appliedCellStyle=="ABC"

 


properties is an object, so that would throw an error—an object is written like {properyName: property}. Not sure what you are going to do in the if statement?