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

[ESTK] Merge Two tables

Participant ,
Jul 24, 2018 Jul 24, 2018

Copy link to clipboard

Copied

Hi all,

Initially i have two tables in indesign, like below

Table 1:

Screen Shot 2018-07-24 at 4.26.05 PM.png

Table 2:

Screen Shot 2018-07-24 at 4.26.11 PM.png

I need to merge above tables the output is,

Screen Shot 2018-07-24 at 4.26.49 PM.png

Please give any helps!!

thanks,

John.

TOPICS
Scripting

Views

2.7K

Translate

Translate

Report

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

Community Expert , Jul 24, 2018 Jul 24, 2018

Found this ancient one:

function merge_tables () {

  var t = app.selection[0].parentStory.tables.everyItem().getElements();

  var rows_to_move = 0;

  for (var i = 1; i < t.length; i++)

    rows_to_move += t.bodyRowCount;

  var moved = 1;

  var rows_length, cells_length, j, k;

  for (var i = 1; i < t.length; i++)

    {

    rows_length = t.bodyRowCount;

    for (j = 0; j < rows_length; j++)

      {

      pb.value = moved++;

      t[0].rows.add ();

      cells_length = t.rows.cells.length;

      for (k = 0; k < ce

...

Votes

Translate

Translate
Community Expert ,
Jul 24, 2018 Jul 24, 2018

Copy link to clipboard

Copied

Found this ancient one:

function merge_tables () {

  var t = app.selection[0].parentStory.tables.everyItem().getElements();

  var rows_to_move = 0;

  for (var i = 1; i < t.length; i++)

    rows_to_move += t.bodyRowCount;

  var moved = 1;

  var rows_length, cells_length, j, k;

  for (var i = 1; i < t.length; i++)

    {

    rows_length = t.bodyRowCount;

    for (j = 0; j < rows_length; j++)

      {

      pb.value = moved++;

      t[0].rows.add ();

      cells_length = t.rows.cells.length;

      for (k = 0; k < cells_length; k++)

        t.rows.cells.texts[0].move (

          LocationOptions.after, t[0].rows[-1].cells.insertionPoints[0]);

      }

    }

  for (var i = t.length-1; i > 0; i--)

    t.remove();

}

if (app.documents.length == 0 || app.selection.length == 0 || app.selection[0].tables.length == 0) {

alert ("Select a story or some text containing more than one table.")

exit()

}

merge_tables();

Peter

Votes

Translate

Translate

Report

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
Participant ,
Jul 24, 2018 Jul 24, 2018

Copy link to clipboard

Copied

Thank you Peter!!

It is working. Sometimes an error encountered while undo these process again in InDesign..

An error is shown below,

The requested action could not be completed because the object no longer exists.

Votes

Translate

Translate

Report

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
Community Expert ,
Jul 24, 2018 Jul 24, 2018

Copy link to clipboard

Copied

Hi John,

you might call the function merge_tables() from a doScript() statement like that:

app.doScript

(

    mergeTables,

    ScriptLanguage.JAVASCRIPT,

    [],

    UndoModes.ENTIRE_SCRIPT,

    "Merge Tables | SCRIPT"

);

// Comment out or remove this line:

// mergeTables()

You then could undo the whole action in one go.

Regards,
Uwe

Votes

Translate

Translate

Report

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
Participant ,
Aug 08, 2018 Aug 08, 2018

Copy link to clipboard

Copied

Hi Peter,

Thanks for this script.

I also need merge table script but whenever I triggered it didn't happen in the file.

query.png

I am using InDesign CC2018 in Mac version.

Please do help.

Thanks,

Amit

Votes

Translate

Translate

Report

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
Community Expert ,
Aug 08, 2018 Aug 08, 2018

Copy link to clipboard

Copied

Hi Amit,

the two tables should share the same story.

Then the script will work.

See into variable t of line 2 of the script. t holds all tables of a single story.

Right now you have two text frames selected that are not threaded.

That means: Two different stories.

So thread the two text frames, select one of it and run the script.

Regards,
Uwe

Votes

Translate

Translate

Report

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
Participant ,
Aug 09, 2018 Aug 09, 2018

Copy link to clipboard

Copied

Thank you Uwe,

I have tried as per your suggestion but there is error showing as below.

query1.png

Please suggest.

Thanks,

Amit

Votes

Translate

Translate

Report

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
Community Expert ,
Aug 09, 2018 Aug 09, 2018

Copy link to clipboard

Copied

Amit -- Just delete that line 13. There must have been a progress bar in that script at some stage.

P.

Votes

Translate

Translate

Report

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
Participant ,
Aug 09, 2018 Aug 09, 2018

Copy link to clipboard

Copied

Thanks Peter for this wonderful script.

My problem is resolved now.

Regards,

Amit

Votes

Translate

Translate

Report

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
Community Expert ,
Aug 09, 2018 Aug 09, 2018

Copy link to clipboard

Copied

Indeed. Varaiable pb is undefined. Maybe some code is missing?

pb is handled as is it an object. Hm. Line 13 in the script does nothing important, I think.

Just assigning a counter to a property of object pb. And then pb is not used anymore.

Suggestion: Comment out or remove line 13 and try again.

Regards,
Uwe

Votes

Translate

Translate

Report

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
Participant ,
Aug 09, 2018 Aug 09, 2018

Copy link to clipboard

Copied

Thanks a lot Uwe.

Now, problem is resolved.

Thanks again for your expert knowledge.

Regards,

Amit

Votes

Translate

Translate

Report

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
Community Expert ,
Aug 15, 2018 Aug 15, 2018

Copy link to clipboard

Copied

LATEST

I hate being late to the party

Worth mentioning this "off the shelf" script that Harbs wrote: Merge Tables Script | in-tools.com

If the answer wasn't in my post, perhaps it might be on my blog at colecandoo!

Votes

Translate

Translate

Report

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