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

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

Community Beginner ,
Jan 17, 2023 Jan 17, 2023

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 🙂

 

TOPICS
Import and export , Print , Scripting , Type
494
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 , Jan 17, 2023 Jan 17, 2023

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

...
Translate
Community Expert ,
Jan 17, 2023 Jan 17, 2023

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
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 Beginner ,
Jan 17, 2023 Jan 17, 2023

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
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 ,
Jan 17, 2023 Jan 17, 2023
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 Beginner ,
Jan 17, 2023 Jan 17, 2023
LATEST

Thank you so much for this - it worked perfectly! 🙂

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