Skip to main content
Inspiring
February 21, 2023
Answered

Access to a paragraph that contains a table [js]

  • February 21, 2023
  • 2 replies
  • 1056 views

Hi,

 

I have a document with two columns design. It’s full of tables. By default, the paragraphs that contains a table expands the two columns, the text not.

 

I have a script that passes to a function a selected table and give it format. When you launch the script there is a UI window that ask for number of head rows, if the table has foot rows and if the table has to expand to two columns or not.

 

My problem is that I don’t know how to access to the paragraph that contains the table to apply it a style that don't expand to two columns, because the selected table passed to the fuction is a little one.

 

As I said before, the table is selected so its parent is a text frame, then spread, then document.

 

I don’t know if there is a direct access to the paragraph or I have to use a workaround.

 

Thank in advance.

This topic has been closed for replies.
Correct answer FRIdNGE

storyOffset

 

(^/)  The Jedi

2 replies

FRIdNGE
FRIdNGECorrect answer
February 22, 2023

storyOffset

 

(^/)  The Jedi

nicoshAuthor
Inspiring
February 22, 2023

While help arrived, I worked on a workaround... I give a name to one column table (oneCol) and in another script find the tables with that name via '<0016>'

 

oneColStyle= app.activeDocument.paragraphStyles.itemByName('tableOneCol');

tableOneCol();

function tableOneCol() {
  app.findChangeTextOptions.includeFootnotes = false;
  app.findChangeTextOptions.caseSensitive = true;
  app.findChangeTextOptions.wholeWord = true;
  app.findTextPreferences = null;
  app.findTextPreferences = app.changeTextPreferences = null;
  app.findTextPreferences.findWhat = "<0016>";
  var results = app.activeDocument.findText();
  for (var i = 0; i < results.length; i++) {
    var tablas = results[i].paragraphs.item(0).tables;
    for (var j = 0; j < tablas.length; j++) {
      if (tablas[j].name == 'oneCol') {
        results[i].paragraphs[0].appliedParagraphStyle = oneColStyle;
      }     
    }    
  }
  alert('Done it')
}

  @FRIdNGE thanks

so easy

FRIdNGE
February 22, 2023

Enough:

 

var myTables = app.activeDocument.stories.everyItem().tables.everyItem().getElements();
for ( var t = 0; t < myTables.length; t++ ) if ( myTables[t].name == 'oneCol' ) myTables[t].storyOffset.appliedParagraphStyle = 'tableOneCol';
alert('Done it')

 

(^/)

Mike Witherell
Community Expert
Community Expert
February 22, 2023

Could you post your code?

Mike Witherell
nicoshAuthor
Inspiring
February 22, 2023

@Mike Witherell thank you for your interest but the script is 650 lines code, it's probably not the best script but it works for me.

@FRIdNGE give me an easy and clean solution.