Skip navigation
Currently Being Moderated

Swapping columns in table

Oct 19, 2010 9:09 PM

Is there a way to cut and paste  columns in a table in CS5? I need to swap the position of two table columns in a document with numerous tables. The tables are complete and the colums I need to swap are of different widths. Is there a way to cut the column with its contence and then paste it in a new position in the table?

 
Replies
  • Currently Being Moderated
    Oct 20, 2010 12:52 AM   in reply to prds

    Not that I know of. You can copy and paste content, but not a whole column with width and all. And it is not covered by table styles either as far as I know. I'd personally love to be able to drag and drop cells, columns, rows etc inclduing their formatting and size and content within and between tables. But that you cannot unfortunately. IDs tables are far from as flexible as those in MS Word are. Much remains to be done there.

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 20, 2010 2:05 AM   in reply to Nini Tjäder

    +1

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 20, 2010 6:36 AM   in reply to prds

    It's scriptable. It's more cumbersome than swapping letters, lines, and paragraphs because columns and rows have no move method. But the below script swaps the selected column and the one on the left. "Selected" means: with an insertion point in any of the cells (if you select a column or some cells, it won't work). The script probably makes a pig of tables with merged cells, so be careful.

     

     

     

    try
        {
        var source = app.selection[0].parent.parentColumn;
        var table = source.parent;
        var ix = source.index
        var target = table.columns.add(LocationOptions.before, table.columns[ix-1]);
        var source = table.columns[ix+1];
        target.width = source.width;
        for (var i = source.cells.length-1; i > -1; i--)
            source.cells[i].texts[0].move (LocationOptions.after, target.cells[i].insertionPoints[0]);
        source.remove();
        }
    catch (_) {}

     

    Peter

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 20, 2010 6:48 AM   in reply to Peter Kahrel

    Peter, I'm far too busy to try for myself, but I was thinking of app.cut & app.paste -- these work well with entire columns, provided you create a blank column to paste into. It works like that in the interface.

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 20, 2010 6:58 AM   in reply to [Jongware]

    You're quite right, Theun!

     

     

    try
        {
        var source = app.selection[0].parent.parentColumn;
        var table = source.parent;
        var ix = source.index;
        var target = table.columns.add(LocationOptions.before, table.columns[ix-1]);
        var source = table.columns[ix+1];
        target.width = source.width;
        source.select(); app.cut();
        target.select(); app.paste();
        target.cells[0].insertionPoints[0].select();
        }
    catch (_) {}
     
    |
    Mark as:
  • Currently Being Moderated
    Jul 31, 2012 12:41 PM   in reply to Peter Kahrel

    I have searched for a script like this to swap the content of two colums, maintaining the formatting of the destination cell.

     

    This seems to be something close, but if I paste the above into the AppleScript Editor some kind of "header" and "footer" is missing I think.

     

    Do you have a solution or a tip?

     

    BR Nina Storm

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 31, 2012 12:50 PM   in reply to Nina_Storm

    Nina,

     

    The above scripts are ExtendScripts (Adobe's version of JavaScript) Use a text editor (making sure that you save as plain text, not RTF) and save the files with a .jsx extension. Put the resulting file in Adobe InDesign CS5.5 ( or what ever version)/Scripts/Scripts panel and then use Window>Utilities>Scripts and double click to run the script.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 31, 2012 1:09 PM   in reply to Larry G. Schneider

    Thank you :-)

     

    I love it. I missed the line "try" and Peters description of not selecting just standing :-)

     

    Now I wonder if it is possible to apply a shortcut to a script?

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 31, 2012 1:13 PM   in reply to Nina_Storm

    Oh yes - Cari explains how to ad a shortcut to a script:

    http://carijansen.com/2008/01/13/tip-067/

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 31, 2012 1:23 PM   in reply to Nina_Storm

    Okay - I can only use it in very few situations.

     

    Dave Saunders updated version of PopTabUnleashed is of greater help as it doesn’t copy the source formats and I can avoid the mess if cells are merged.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 1, 2012 2:37 AM   in reply to Nina_Storm

    @Nina – as you may or may have not noticed, Dave's script is working with the plain text contents of a cell (the "contents" property opposed to the "texts" property of the cells you want to copy/paste). Wheras Peter's script is working with the "texts" property where all the formatting information is stored.


    That implies:

     

    1. anchored objects (images or other graphical objects or text frames) will not travel over to the target table, if you are using Dave's script.

     

    2. if the target is pre-populated with formatted text, e.g.:

    "H2O" at the beginning of cell 1 of your target, where the "2" is set to subscript, your pasted text will get the subscript formatting in character two.

     

    3. since loosing all your formatting from the source, "H2O" will not be formatted correctly if you paste to the new target.

     

    Uwe

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 1, 2012 8:53 AM   in reply to prds

    I cut and paste columns in tables every day.  Just insert a new blank column and then place the cut column into it.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 1, 2012 11:25 AM   in reply to bumpandrun

    @Laubender, thanks for explaining, yes I did notice the difference, and I wanted to swap the plain text content of two adjacent columns, but applying the text and cell formatting from the destination colums.

     

    @bumpandrum, I am going to make a heavy annual report ready for InCopy editing and I have to move all last years new figures to be the old figures of this year. Formatted and placed as "old" figures. I want to use as few mouseclicks as possible :-)

    If I just copy and paste I'll bring the formatting of the text and cells, or am I missing something ?

     

    Sorry if this is a poor explanation.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 1, 2012 1:10 PM   in reply to Nina_Storm

    Yes, if you are trying to do it without carrying the formatting over it won't work.  If you copy and paste you get it all.  Sorry if you said that earlier and I missed it.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 2, 2012 7:30 AM   in reply to Nina_Storm

    @Nina – another observation:

    if you transfer text with the "texts" method as shown with the script in post #3 and one of the cells you want to transfer is empty, the formatting of the insertion point in that cell will not travel over. This might or might not be a "problem", if you want to fill the empty cell after the transfer…

     

    Uwe

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 2, 2012 12:04 PM   in reply to Laubender

    @Laubender, I think you shoul use the script from post #5.

    I cannot redo your observation, if I format the entire column including paragraph styles, it doesn't matter if they are empty or not.

    If I have a format applied to an empty cell, the formatting will travel with the cell when swapped using the script from post #5.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 3, 2012 2:02 AM   in reply to Nina_Storm

    I think you should use the script from post #5.

     

    Or writing my own script, which transfers the formatted "texts" without all the other properties of the cell. :-)

    (In opposition to the script in post #5, where the cells properties are swapped, too.)

     

    In InDesign CS5.5 and above, I see a chance to transfer "texts" objects between two or more tables in one script according to the order of selected text frames and their tables. The first selected text frame (by definition) could be the source, all other selected text frames could be the target. Or the last selected text frame of the selection could be the source and all other text frames could be the target…

     

    This is due to the fact (InDesign CS5.5 and CS6), that if you select a couple of page items, the index number of the first selected object is always 0 and the index of the selection is numbered on after the order of the selection the user is doing by holding the shift key and assembling the objects by clicking.

     

    But really, Adobe should add a lot of features to table handling, which, basically is the same a couple of years now (6 to 8 years? I don't know…)

     

    Uwe

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points