Skip to main content
brown1982
Participating Frequently
September 28, 2022
Answered

Find inline tables and apply paragraph style

  • September 28, 2022
  • 1 reply
  • 521 views

Dear Community,

 

Is there a possibility to find tables in the text and provide them with no specific paragraph style ('center' for example) with javascript?

 

Who can help me with this, he/she is a life saver!

This topic has been closed for replies.
Correct answer Peter Kahrel

Also, aint the solution. Still same error.

var style = app.documents[0].paragraphStyleGroups.itemByName( "Tabellen" ).
paragraphStyles.itemByName( "Tabel uitlijning" );


app.findTextPreferences = null;
app.findChangeTextOptions = null;
app.findTextPreferences.findWhat = '<0016>';
found = app.documents[0].findText();
for (i = 0; i < found.length; i++) {
  found[i].tables[0].appliedParagraphStyle = style;
}

Sorry -- this line:

found[i].tables[0].appliedParagraphStyle = style

should be like this:

found[i].appliedParagraphStyle = style

1 reply

Peter Kahrel
Community Expert
Community Expert
September 28, 2022

Not sure I understood "provide them with no specific paragraph style ('center' for example)", you probably meant 'provide them with a specific paragraph style".

 

If that's the case, here's a possible script:

style = app.documents[0].paragraphStyles.item('center');
app.findTextPreferences = null;
app.findChangeTextOptions = null;
app.findTextPreferences.findWhat = '<0016>';
found = app.documents[0].findText();
for (i = 0; i < found.length; i++) {
  found[i].tables[0].appliedParagraphStyle = style;
}

P.

 

brown1982
brown1982Author
Participating Frequently
September 28, 2022

Peter Kahrel the legend! Superthanks.
I'm going to test it right away.
Haven't touched scripts in a few years, and I wasn't very good with them.
And yes i mean: specific paragraph.... i don't know why i put 'no' there 😄