Skip navigation
traveldis2
Currently Being Moderated

convertTextToTable

Aug 7, 2012 5:45 AM

Hi, I want to do this function with a script: Tables can be created from existing text using the convertTextToTable method, or an empty table can be created at any insertion point in a story.

 

1. Select a text (story)

2. Convert to Table with a style

 

3. Then I want to apply some greps and styles within the same script. I already have this point working.

 

I guess it's very simple, but I'm new in this and I haven't found the script, can you help me?

 

Thank u

 
Replies
  • Currently Being Moderated
    Aug 7, 2012 6:10 AM   in reply to traveldis2

    Hi,

     

    the command for text objects:

    convertToTable ([columnSeparator: string][, rowSeparator: string][, numberOfColumns: number=1])

     

    A infoplace: http://jongware.mit.edu/idcs5.5js_html/idcs5.5js/pc_Text.html#convertT oTable

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 7, 2012 10:22 AM   in reply to traveldis2

    @traveldis2 – see the following example:

     

    //Let's assume that we selected one single text frame only:
    var myTextFrame = app.selection[0];
     
    //You can access the whole story of the text frame (and all of its threadded text frames) by:
    var myStory = myTextFrame.parentStory;
     
    //Then we need the "texts" object of that story:
    var myTexts = myStory.texts[0];
     
    //We now can convert that "texts" object to a table:
     
    //First argument is the column separator string (in this case a "tabulator")
    //Second argument in this case is different from the first one and represents the row separator (a "return")
     
    //Both arguments are separated by a "comma"
     
    myTexts.convertToTable("\t","\r");
    

     

    That would convert the story to a table, but we have no immediate access to that table, if we want to format it, etc.pp.

     

    So we could shorten the above code a bit and getting access to the table by introducing a variable for our table:

     

    //If you want to work on with the table, you'll need a handle on it. That means a variable for the table:
    //And we could write this a little shorter:
     
    var myTable = app.selection[0].parentStory.texts[0].convertToTable("\t","\r");
     
    //The default width of the table is the width of the first container of the story.
    //All columns are devided evenly in width.
     
    //If you do not want that, adjust the width of all the columns in one go:
     
    //Example with Millimeter unit:
    myTable.columns.everyItem().width = "25 mm";
    

     

     

    Uwe

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (1)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points