1

In my InDesign document there are many tables, each table is on separate page with autoflowing text. There is a text above each table without paragraph returns. I want that text to move from there to table's second cell. This I want to do for all the tables in my active document. Basically I need to move text from other place into InDesign table. Can someone please help. Manually doing this is very time consuming and panic. There are many tables in my InDesign document.

this is the what I am expecting which is shown in attached screenshot

2
  • Yes. I'm sure it can be done pretty easy, but there are some details the actual solution depends on. It's need to test on a more or less real text. Can you provide example of your IDML file? Commented Mar 24, 2024 at 9:42
  • 1
    drive.google.com/file/d/1e511MRh8xxKl43un3Q-mIMrdhetCZOIh/… @YuriKhristich Khristich this is the link of idml file. Commented Mar 24, 2024 at 10:20

1 Answer 1

0

Select the text frame and try to run this code:

var story = app.selection[0].parentStory;
var pgfs = story.paragraphs;

for (var i=0; i<pgfs.length; i++) {
    if (pgfs[i].tables.length == 0) continue;

    var table = pgfs[i].tables[0];
    var cell = table.rows[0].cells[1];
    var contents = pgfs[i].lines[0].contents;

    app.findTextPreferences = NothingEnum.NOTHING;
    app.changeTextPreferences = NothingEnum.NOTHING;
    app.findTextPreferences.findWhat = contents;
    app.changeTextPreferences.changeTo = '';
    pgfs[i].changeText();

    cell.contents = contents;
}

Or, even simpler solution without changeText():

var story = app.selection[0].parentStory;
var pgfs = story.paragraphs;

for (var i=0; i<pgfs.length; i++) {
    if (pgfs[i].tables.length == 0) continue;
    pgfs[i].tables[0].rows[0].cells[1].contents = pgfs[i].lines[0].contents;
    pgfs[i].lines[0].contents = '';
}

Update

To move the footnotes you can try this:

var story = app.selection[0].parentStory;
var pgfs = story.paragraphs;

app.findGrepPreferences = NothingEnum.NOTHING;
app.findGrepPreferences.findWhat = "footnote\\s+\\d+.+"; // <-- your GREP

for (var i=pgfs.length-1; i>=0; i--) {              // loop backward
    if (pgfs[i].tables.length == 0) continue;       // skip if no table
    var finds = pgfs[i].findGrep();
    if (finds.length == 0) continue;                // skip if noting was found
    pgfs[i].insertionPoints[-1].contents = finds[0].contents;
    finds[0].contents = '';
}

Before:

enter image description here

After:

enter image description here

Sign up to request clarification or add additional context in comments.

4 Comments

Hi Yuri Khristich, one more addition I want to add in the script, I want to find any specific text in the table using GREP find/replace and if found then move that text to below table. For example I want to find "Footnote" text from all the tables and move it to below table. In the below link I have attached the idml file. drive.google.com/file/d/1Sb4N5kMDYeCYHBHO5fLKcwTAm84YpT-z/…
Hi! I just updated my answer. You can handle the footnotes as a second script or to add it at the end of the first script.
Thank you so much for your help 😊 really appreciated 🙏 your script is working like a charm.
@tofiktamboli If that's the case, you should mark this answer as correct so others know your question has been answered

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.