How do I convert rows into columns (or vice versa) in Calc?

I have some data spread out in rows. Now I’ve entered it, I really would prefer to see it in columns. Is there a way to do this automatically in Calc (i.e., change a row presentation into columns)?

And if I can do it as columns --> rows, I expect it will also work for the opposite switch, rows --> columns. Correct?

I would like to accomplish something similar, however preserving formulas. It seems as if it may be possible with macros by (1) specifying a range, (2) iterating over it (3) calculating the transposed coordinates for the current cell, and (4) copying the current cell contents to the transposed location. I would appreciate any hints or pointers to sample code.

My attempt using perl is here: Debian paste error

Running this code got many errors: ‘Element is already part of tree’

As it happens, this is quite easily done:

  1. Select the area of data you want to “convert”, e.g., click top-left cell, then shift-click bottom right cell. You should how have copied all the rows of data that you want to convert into columns of data.
  2. Hit CTRL-C to copy.
  3. Go to a new worksheet, click the cell where you want to paste your new columns.
  4. Either hit Shift-CTRL-V, or use Edit > Paste Special... from the toolbar to bring up this dialog:
  5. Ensure that the Transpose option is selected, then click OK. Done!

The same process works in either direction (cols-to-rows, rows-to-cols).

Credit: I couldn’t find this on AskLibo, and have followed these Excel instructions.