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?
the command for text objects:
convertToTable ([columnSeparator: string][, rowSeparator: string][, numberOfColumns: number=1])
@traveldis2 – see the following example:
//Let's assume that we selected one single text frame only: var myTextFrame = app.selection; //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; //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.parentStory.texts.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";