Skip to main content
Participant
November 3, 2016
Answered

table position

  • November 3, 2016
  • 1 reply
  • 1894 views

I want to create 5 small tables in a textframe side by side. So I create them this way:

for(var i = 0; i < 5; i++) {

    var table = textFrame.insertionPoints[-1].tables.add();

    table.bodyRowCount = 2;

    table.columnCount = 1;

    table.width = 16;

    }

However, this code positions the tables one below the other and not side by side.

I haven't found out so far how I can achieve this. Help very appreciated.

This topic has been closed for replies.
Correct answer Laubender

I've done it into auto-resized text frames! Interesting way! 

(^/)


Hi together,

yes—using anchored frames is possible.

Here some code:

// Text frame selected:

var textFrame = app.selection[0];

// Let's build a text frame with a table somewhere on the spread:

var frameWithTable = app.documents[0].layoutWindows[0].activeSpread.textFrames.add

(

    {

        geometricBounds : [0,0,100,16],

        strokeWidth : 0,

        strokeColor : "None",

        fillColor : "None"

    }

);

// Adding a table:

frameWithTable.insertionPoints[0].tables.add

(

    {

        bodyRowCount : 2,

        columnCount : 1,

        width : 16,

        contents : ["Cell 1", "Cell 2"]

    }

);

// Let's fit the frame to the table:

frameWithTable.fit(FitOptions.FRAME_TO_CONTENT);

// Duplicate and anchor the duplicates to the selected text frame:

for(var n=0;n<5;n++)

{

    var dup = frameWithTable.duplicate();

    dup.anchoredObjectSettings.insertAnchoredObject

    (

        textFrame.parentStory.insertionPoints[-1] ,

        AnchorPosition.INLINE_POSITION

    );

  

    // Maybe we need a separator character between the frames?

    textFrame.parentStory.insertionPoints[-1].contents = " ";

}

// Remove the frame we built on the spread:

frameWithTable.remove();

Have fun!

Cheers,

Uwe

1 reply

Jump_Over
Legend
November 3, 2016

Hi,

Are you able to do it manually (in GUI)?

Participant
November 3, 2016

No! :-)

I have tried to pack the tables into textframes but that didn't work well.

Obi-wan Kenobi
Legend
November 3, 2016

I've done it into auto-resized text frames! Interesting way! 

(^/)