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

move text from one table field to another

Community Beginner ,
May 15, 2018 May 15, 2018

Copy link to clipboard

Copied

Hi,

I am looking for help moving text from one table field to another and have around 80 tables to modify in one document.

The text I want to move has it's own para style which will hopefully help with the script.

Here is an example of what I currently have:

Column 1Column 2Column 3
empty field

1234 (with paragraph style 'partno' followed by a return)

ABCD (with paragraph style 'desc')

qty
empty field

123456 (with paragraph style 'partno' followed by a return)

ABCD (with paragraph style 'desc')

qty
empty field

12345 (with paragraph style 'partno' followed by a return)

ABCD (with paragraph style 'desc')

qty

Here is an example of the finished result I would like to achieve:

Column 1Column 2Column 3
1234

ABCD (description with paragraph style 'desc')

qty
123456

ABCD (description with paragraph style 'desc')

qty
12345

ABCD (description with paragraph style 'desc')

qty


I am just discovering the amazing things that can be done using scripts in indesign and how efficient they make laborious tasks.

Appreciate any help I receive.

thanks

David

TOPICS
Scripting

Views

1.3K

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

Guide , May 18, 2018 May 18, 2018

Hi,

Uwe is totally right! … Be careful on what you ask and what you provide! …

Once again, this could work on your file sample but at your own risks! [if safer, think about paying a scripter to achieve such a script!]

var myRows = app.activeDocument.stories.everyItem().tables.everyItem().rows.everyItem().getElements(), 

R = myRows.length,  r; 

for ( r = 0; r < R; r++ ) {

    try {

        if ( myRows.cells[1].paragraphs[0].appliedParagraphStyle.name == "partno" ) {

            myRows.cells[1].paragrap

...

Votes

Translate

Translate
Community Expert ,
May 16, 2018 May 16, 2018

Copy link to clipboard

Copied

Hi,

You should be able to use code something like this, I have made it more verbose than is probably needed as you say you are just discovering what can be done, and I wanted to make it as easy to follow as possible.

// get active document

var myDoc = app.activeDocument;

// get all tables from that document

var myPageItems = myDoc.pageItems.everyItem();

var myTables = myPageItems.tables.everyItem().getElements();

// for each table

for ( var i = 0; i < myTables.length; i++)

{

    // get all cells

    var curTable = myTables;

    var curTableCells = curTable.cells;

    // for each cell

    for ( var j = 0; j < curTableCells.length; j++)

    {

        var curCell = curTableCells;

        // get all text ranges - a text range is made everytime a style is changed

        var curTextStyleRanges = curCell.textStyleRanges;

       

        for ( var k = 0; k < curTextStyleRanges.length; k++)

        {

            var curTextStyleRange = curTextStyleRanges;

            // check the name of the text ranges appliedParagraphStyle

            if ( curTextStyleRange.appliedParagraphStyle.name === "partno")

            {

                // as your example the empty cell is always the one before the cell we currently have

                var jMinusOne = j - 1;

                var newDestCell = curTableCells [jMinusOne];

                // only copy the cells contents that match our range

                newDestCell.contents = curTextStyleRange.contents;

                // set the new contents to have the same paragraph style

                newDestCell.textStyleRanges[0].appliedParagraphStyle = myDoc.paragraphStyles.itemByName("partno");

                // delete the contents from the original cell

                curTextStyleRange.remove();               

            }

        }

    }

}

Hope this helps

Malcolm

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 Beginner ,
May 16, 2018 May 16, 2018

Copy link to clipboard

Copied

Hi Malcolm, thanks for helping out.

I ran your script and get the following error:

Screen Shot 2018-05-17 at 10.09.52 AM.png

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 ,
May 17, 2018 May 17, 2018

Copy link to clipboard

Copied

HI,

Can you provide a sample document so that we can see what the issues is, it is probably just some graphic object or other non text item, which doesn't have the properties required by the scripts.

Regards

Malcolm

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 Beginner ,
May 18, 2018 May 18, 2018

Copy link to clipboard

Copied

Hi Malcolm, thank you.

here is a url to download a sample spread. - hopefully this shines some light on the issue.

Dropbox - sample.indd

I do hope it is a simple thing to resolve. I also believe we are in opposite hemispheres but if I receive a reply - which may be late evening for me - I will hopefully be able to check on any feedback I receive.

thanks Again for your help

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 ,
May 18, 2018 May 18, 2018

Copy link to clipboard

Copied

Hi David,

no wonder Michel's script is tripping. Your sample InDesign document presents a totally different structure in the table cells compared with what you presented in your initial post.

The best bet—as seen from the sample doc—is to inspect the fill color of cell 1 and cell 2 of a given row. If it is the same and if it is "Titanium" and if the first cell is empty, then inspect cell 2. If cell two contains two paragraphs and if paragraph one consists of numbers only, then move paragraph one to the empty cell 1 and finally get rid of the pargaraph sign at the end of the paragraph.

That would be a kind of algorithm that could work. However it could fail silently or do the wrong thing, if anywhere in your document is an exception. Maybe a cell is not filled with right fill color or white space sneaked in in the cell that should be empty or in the paragraph that should contain only numbers. Other exceptions are possible as well… 🙂

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
Community Expert ,
May 18, 2018 May 18, 2018

Copy link to clipboard

Copied

Oh, and another thing: Your sample document has no paragraph style named "desc". Another thing, that could go wrong, if a script is working with that to identify the right cell.

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
Community Beginner ,
May 18, 2018 May 18, 2018

Copy link to clipboard

Copied

Hi Uwe,

Thanks for the honest feedback.

I guess my thinking was a script would look for text styled partno in

column 2, check the row it’s in then copy ( cut) the partno text Into

column 1 of the corresponding row. Then find the next instance of partno...

but i have no idea about scripting hence asking for some help.

Even if a script helped with 90% it would save me time.

Thanks

David

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
Guide ,
May 18, 2018 May 18, 2018

Copy link to clipboard

Copied

Hi,

Uwe is totally right! … Be careful on what you ask and what you provide! …

Once again, this could work on your file sample but at your own risks! [if safer, think about paying a scripter to achieve such a script!]

var myRows = app.activeDocument.stories.everyItem().tables.everyItem().rows.everyItem().getElements(), 

R = myRows.length,  r; 

for ( r = 0; r < R; r++ ) {

    try {

        if ( myRows.cells[1].paragraphs[0].appliedParagraphStyle.name == "partno" ) {

            myRows.cells[1].paragraphs[0].characters.itemByRange(0, myRows.cells[1].paragraphs[0].characters.length-2).move(LocationOptions.after, myRows.cells[0].insertionPoints[0]); 

            myRows.cells[1].paragraphs[0].contents = "";

        }

    } catch(e) {}

}

Best,

Michel

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 Beginner ,
May 22, 2018 May 22, 2018

Copy link to clipboard

Copied

LATEST

Hi Michel, thank you for your help with the script, it works well and has saved a lot of tedious work.

I did find that some text in the document had a paragraph style and character style which I think cause the script to falter but after removing the character style and making sure the para style was not is a folder all was good.

thanks again

David

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 ,
May 16, 2018 May 16, 2018

Copy link to clipboard

Copied

Hi David,

if you like to move text, would you like the formatting of the text stay the same after it is moved?

If that's the case one would use method move() with object Text and would not use property contents.

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
Guide ,
May 16, 2018 May 16, 2018

Copy link to clipboard

Copied

A simplistic and short writing of a way working in such a sample [transfer of the first para of each cell of the second column to the corresponding cell of the first column]!

var myRows = app.activeDocument.stories.everyItem().tables.everyItem().rows.everyItem().getElements(),

R = myRows.length,  r;

for ( r = 0; r < R; r++ ) {

    myRows.cells[1].paragraphs[0].characters.itemByRange(0, myRows.cells[1].paragraphs[0].characters.length-2).move(LocationOptions.after, myRows.cells[0].insertionPoints[0]);

    myRows.cells[1].paragraphs[0].contents = "";

}

Best,

Michel, from FRIdNGE

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 Beginner ,
May 16, 2018 May 16, 2018

Copy link to clipboard

Copied

Hi Michel, thank you your help.

I ran your script and get the following error:

Screen Shot 2018-05-17 at 10.09.00 AM.png

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 Beginner ,
May 16, 2018 May 16, 2018

Copy link to clipboard

Copied

Hi Uwe,

you are right, the paragraph formatting of the 1st para in column 2 would remain the same once it was moved to column 1.

thanks for your help

David

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 ,
May 17, 2018 May 17, 2018

Copy link to clipboard

Copied

Hi David,

then the approach of Michel's script is the right one.

But maybe there are some exceptions in one of your tables in the document.

E.g. some empty cells in column two. Or some graphic cells here and there.

To make that script run without errors some if statements should be included.

But for that it would be perfect to see into the original InDesign document.

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