Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

not able to merge table cells

New Here ,
Jul 16, 2013 Jul 16, 2013

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

TOPICS
Scripting
1.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Contributor , Jul 16, 2013 Jul 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

Translate
Contributor ,
Jul 16, 2013 Jul 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 16, 2013 Jul 16, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 17, 2013 Jul 17, 2013

hello dave,,

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jul 18, 2013 Jul 18, 2013
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 16, 2013 Jul 16, 2013

want_tab.JPGmaintab.JPG

dear dev i have upload three images of tables

1- main_tab means what is my actual table

2- want_tab- which i need to convert my table

3-after_script_tab- this is the converted table after using my scripting

after_scripting_tab.JPG

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jul 16, 2013 Jul 16, 2013

Hi,

Notice before merge 4 that your

table.columns[3].rows.length IS NOT EQUAL to table.columns[3].cells.length;

(6 != 5)

I suggest to set your merge horizontally

(i.e using: table.rows.cells[1] instead of table.columns[1].cells)

______________________

edited: wrong suggestion!!!

     since you are editing a table vertically first -

     its rows[0].cells.length == 4 and the rest of rows.cells.length ==3

     With your particular goal:

     move merge 1 to the end of steps

Jarek

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 17, 2013 Jul 17, 2013

hello jarek,,

you are right for my perticular case

but my script comes out from code sequentially merge1 to merge 4

how could i apply 1st merge in end

i am talking about various tables and their merges

thanks

ajay

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 17, 2013 Jul 17, 2013

hi,

dear i just want to know how will i find or get the return value of any variable in java script through indesign object model??

ex- "var tab= table.rows.length;"

i just want to know the return value in variable "tab" while debug the script.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 17, 2013 Jul 17, 2013

hi,

dear i  want to know how will i find or get the return value of any variable in java script through indesign object model??

ex- "var tab= table.rows.length;"

i just want to know the return value in variable "tab" while debug the script.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines