I’m trying to add a cell style called smsCodeCellStyle to the entire header row of two tables. This cell style contains a fill color for the cell and a paragraph style with a text fill color.
Here’s a part of one of the generated tables, so you can see the desired effect:
This is my current approach, which works, but seems janky. This approach also prevents other parts of the cell styles from being applied:
for (let table = 0; table < createdTables.length; table ++) { // for each table...
createdTables[table].headerRowCount++; // add the header row
for (let cell = 0; cell < createdTables[table].rows.firstItem().cells.length; cell++) { // for each cell in the header row...
const currentCell = createdTables[table].rows.firstItem().cells.item(cell); // get the cell
currentCell.fillColor = (smsCodeCellStyle.fillColor as Color).name; // do some magic to get the colors
currentCell.texts.firstItem().fillColor = (
(smsCodeCellStyle.appliedParagraphStyle as ParagraphStyle)
.fillColor as Color
).name;
}
}
But ideally I’d just have this, which seems like it would work, but crashes the application:
Hey thanks for giving it a shot. But something is still fishy. I’ve copied your code exactly, commented out all my other code, and I’m still getting the crash. I also tried it with a different cell style…
Did your tables have any content in them when you ran the script?
I’ve also tried adding the style on table creation, no luck.
I’m still able to set the cell contents, but not the style.
I have tried adding app.clearOverridesWhenApplyingStyle = true; at the top of my code and currentCell.texts.firstItem().clearOverrides(OverrideType.ALL); before I change the style. I’ve also tried my original approach through the dev console on a manually-created table.
In that original code, smsCodeCellStyle was a CellStyle object. However I think I solved the actual problem, and it involved adding .name to the end of the object. So