Skip to main content
Known Participant
Jan 17, 2023 9:58 AM UTC
Answered

Applying Cell Style to specific cells in table, based on text - Do I use a script or GREP?

Hi all!

 

I'm currently in the middle of designing a wall planner, and need to add a certain cell style to cells which have the Saturday (Sa)  / Sunday (Su) abbreviations in them?

I have used GREP in order to change the text styles, not cannot find a way for GREP to change the cell style based on the text.

Does anyone know of a way to do this using GREP, or know of a script which can be run to find all cells which have "Sa" / "Su" in them, and change their cell style to one named "weekends"?

 

Much appreciated if anyone can help me out 🙂

 

This topic is closed to new replies. Start a new post to keep the conversation going.
Manan JoshiCorrect answer
Community Expert
Jan 17, 2023 10:49 AM UTC

Hi @KuriousKatie,

Try the following code

app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.NOTHING;
app.findGrepPreferences.findWhat = "^Sa|Su$"
var f = app.documents[0].findGrep()
for(var i = 0; i < f.length; i++){
	var p = f[i].parent
	if(p instanceof Cell)
		p.appliedCellStyle = "MyStyle" //Change the style name to the one you want to apply
		
}
app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.NOTHING;

P.S. :- Change the name of the cell style(MyStyle) to your style name

-Manan

-Manan

4 replies

Manan JoshiCommunity ExpertCorrect answer
Community Expert
Jan 17, 2023 10:49 AM UTC

Hi @KuriousKatie,

Try the following code

app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.NOTHING;
app.findGrepPreferences.findWhat = "^Sa|Su$"
var f = app.documents[0].findGrep()
for(var i = 0; i < f.length; i++){
	var p = f[i].parent
	if(p instanceof Cell)
		p.appliedCellStyle = "MyStyle" //Change the style name to the one you want to apply
		
}
app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.NOTHING;

P.S. :- Change the name of the cell style(MyStyle) to your style name

-Manan

Translate
-Manan
Known Participant
Jan 17, 2023 10:56 AM UTC

Hi Manan,

 

Thank you for your help! 🙂

Sorry if it's a silly question, but - do I need to save this as a .jsx script?

Translate
Community Expert
Jan 17, 2023 11:13 AM UTC
-Manan