Rotate Table

This utility creates a new table that is a copy of the selected table, but with columns and rows swapped round.


// Rotate Table

Object oldTable = null
Object oldRow = null
Object oldCell = null

Object newTable = null
Object newRow = null
Object newCell = null

int c = 0
int r = 0

Array a = create(1,1)

oldCell = current Object

if (null oldCell || !cell(oldCell))
{
 infoBox("No table selected!")
 halt
}

oldTable = getTable(oldCell)

for oldRow in table(oldTable) do
{
 c = 0
 for oldCell in row(oldRow) do
 {
  put(a, (string oldCell."Object Text" ""), r, c)
  c++
 }
 
 r++
}

print c " columns " r " rows \n"

newTable = table(oldTable, c, r)

c = 0
r = 0
for newRow in table(newTable) do
{
 c = 0
 for newCell in row(newRow) do
 {
  if (c == 0)
  {
   newCell."Object Text" = richText("{\\b " (string get(a, c, r)) "}")
  }
  else
  {
   newCell."Object Text" = (string get(a, c, r))
  }
  c++
 }
 
 r++
}