Skip to main content
Participating Frequently
July 16, 2013
Answered

not able to merge table cells

  • July 16, 2013
  • 1 reply
  • 1952 views

hello forum,

i am using Indesign 5.5, having problem to merge table cells through scripting.

i want to merge multiple cells in a table.

i have merge first three merge coorectly, but my script not able to merge forth merge.

i am using,

var myDocument=app.activeDocument;

var myTextFrame=myDocument.spreads.item(0).textFrames.item("Spread0TxtFrame0");

var table =myTextFrame.tables.firstItem();

var t = table.rows.length;

var f = table.rows.length - (t-start row count) // **start row count is intiger indicates merge start row

var fn=table.rows.length - (t-end row count)

table.columns[1].cells.merge table.columns[2].cells[fn];      ////* [1]=starting column,,,[2]= end column

when i does pass the value for first three merge it works but when i use for forth merge indxing is change for value of rows.what i am passing into f and fn.

example:-

var t = table.rows.length;

var f = table.rows.length - (t-0);

var fn=table.rows.length - (t-5);

table.columns[0].cells.merge table.columns[0].cells[fn];   // it is for first merge

var t = table.rows.length;

var f = table.rows.length - (t-0);

var fn=table.rows.length - (t-0);

table.columns[2].cells.merge table.columns[3].cells[fn];   // it is for second merge

var t = table.rows.length;

var f = table.rows.length - (t-1);

var fn=table.rows.length - (t-1);

table.columns[1].cells.merge table.columns[2].cells[fn];   // it is for third merge

var t = table.rows.length;

var f = table.rows.length - (t-3);

var fn=table.rows.length - (t-3);   

table.columns[1].cells.merge table.columns[3].cells[fn];   // it is for forth merge

i get

an extra row merges with forth one..

seperately all four merge works but when i fire script with all it merge wrong cells in forth merge.

please correct me where i am wrong in script.

your answer will be apriciated.

Thanks

Ajay

This topic has been closed for replies.
Correct answer DaveSofTypefi

How many rows does this table have in the first place? The most likely problem is that because of the previous merges the number of rows left is such that there aren't enough rows left for f to be formed properly.

I may be off base here because I can't see the screen captures you tried to post.

Dave

1 reply

DaveSofTypefiCorrect answer
Inspiring
July 16, 2013

How many rows does this table have in the first place? The most likely problem is that because of the previous merges the number of rows left is such that there aren't enough rows left for f to be formed properly.

I may be off base here because I can't see the screen captures you tried to post.

Dave

ajay259Author
Participating Frequently
July 17, 2013

hello dev,

i have 6 rows and 4 columns no footer no header,

and i did merge

1st mergecell:- from row1 column1  to  row6 column1

here is the syntax:-

var t = table.rows.length;

var f = table.rows.length - (t-0);

var fn=table.rows.length - (t-5);

table.columns[0].cells.merge table.columns[0].cells[fn];

2nd mergecell:- from row1 column3 to row1 column4

syntax:-

var t = table.rows.length;

var f = table.rows.length - (t-0);

var fn=table.rows.length - (t-0);

table.columns[2].cells.merge table.columns[3].cells[fn];

3rd mergecell:- from row2 column2 to row2 column3

syntax:-

var t = table.rows.length;

var f = table.rows.length - (t-1);

var fn=table.rows.length - (t-1);

table.columns[1].cells.merge table.columns[2].cells[fn];

4rt mergecell:- from row4 column2 to row4 column4

i use

var t = table.rows.length;

var f = table.rows.length - (t-3);

var fn=table.rows.length - (t-3);    // problem is here it takes (t-2) instead of (t-3)

table.columns[1].cells.merge table.columns[3].cells[fn];

** all value having 0 indexing

Inspiring
July 18, 2013

hello dave,,

i am waiting for your response, please find the attachment tables and take a overview on situation.


Your posted script has syntax errors so I couldn't find what you were doing wrong because the script won't run as posted. Can you post a version that actually exhibits the problem you're trying to solve.

But, from what has gone before, you're probably overlooking the fact that your script is changing the number of rows as it does each step so what you think of as static values are actually changing during the course of the script.

Dave