Switching Rows and Columns in an InDesign Table
Sometimes you have a table in InDesign that looks like this:
A | B | C |
D | E | F |
G | H | I |
But you want it to look like this:
A | D | G |
B | E | H |
C | F | I |
That is, you want to transpose (switch) the columns and rows so that the content “flows” down the first column, then down the second column, and so on.
There is no obvious way to do this in InDesign, but you can do it either with the help of Excel, a free script, or an excellent plug-in.
The Excel Route
As long as the table is relatively simple, the easiest and fastest route is to:
- Select all the cells (click in one cell and then press Command-Option-A, or Ctrl-Alt-A)
- Copy them to the clipboard (Cmd/Ctrl-C)
- Switch to Microsoft Excel and open a new document
- Choose Edit > Paste
- Then select the cells again and copy them to the clipboard. (Yes, you need to do this again, in order to take advantage of the next feature.)
- Choose Edit > Paste Special
- In the Paste Special dialog box, turn on the Transpose checkbox:
When you click OK, the table will be reversed! Now you can copy the cells one last time, return to InDesign, and paste (assuming the table cells are still selected there).
(If, when you paste, it doesn’t look right — for example, if the whole table ends up in the first cell of the InDesign table — then it’s possible that you need to open InDesign’s Preferences dialog box, choose the Clipboard Handling pane, and set the “When Pasting Text and Tables from Other Applications” to “Text”.)
Here’s an example… before and after:
The Script
In trying to find a solution for this problem, I discovered an old script from 2006, written by Iain Anderson. Amazingly, it seems to work just as well today, in InDesign CC, as it did back then. Here’s our InDesign FAQ, which includes links on how to install scripts.
Note that when you run this script, you need to select the text frame (not the table), and it will only affect the first table in the story.
The Plug-in
The ActiveTables plug-in, which we mentioned back on this article and which you can also find on the DTP Tools site, has a wide array of cool table features. If you’re using InDesign CC, you can get Active Tables as part of the DTP Cloud option (all the DTP Tools plug-ins for one low price per month or per year).
Of course, if your table is complicated (with merged cells and so on), all bets are off with any of these techniques. But for a simple table that needs flipping, these techniques should do the trick!
Hey there — amazed that someone found my old script after all these years! Glad it’s still useful.
And people are still finding it for the first time and still it’s going strong in CC18! Comments are closed in your original thread so I’ll have to thank you here and hope you subscribe to notifications. Thank you Iain!
I might have spoken a little too soon, it doesn’t seem to like header rows – the net result being that it removes a column of data from your table. There is however a simple enough remedy, convert your header row to body before running the script.
Still glad it’s still helpful! And yes, you’re right, it doesn’t deal well with header rows, and I don’t think it ever did.
Works well but quite heavy on the cpu if table is large (50+ rows)
It doesn’t transpose cells which have text fields/ combo boxes in them. I just get a error message (Error number 45…)
Is there any way i can change the script?