Copy link to clipboard
Copied
Hi all,
Initially i have two tables in indesign, like below
Table 1:
Table 2:
I need to merge above tables the output is,
Please give any helps!!
thanks,
John.
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
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
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.
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
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.
I am using InDesign CC2018 in Mac version.
Please do help.
Thanks,
Amit
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
Copy link to clipboard
Copied
Thank you Uwe,
I have tried as per your suggestion but there is error showing as below.
Please suggest.
Thanks,
Amit
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.
Copy link to clipboard
Copied
Thanks Peter for this wonderful script.
My problem is resolved now.
Regards,
Amit
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
Copy link to clipboard
Copied
Thanks a lot Uwe.
Now, problem is resolved.
Thanks again for your expert knowledge.
Regards,
Amit
Copy link to clipboard
Copied
I hate being late to the party
Worth mentioning this "off the shelf" script that Harbs wrote: Merge Tables Script | in-tools.com