Saturday, January 24, 2009

OpenOffice.org Base: Export Table or Rearrange Fields

As of version 2.4, when you create a table in OpenOffice.org Base, it is not obvious how to export it (for example, to a spreadsheet, or a word processing document). Also, once you have created a table definition and entered data into it, you can no longer change the order of columns (any new columns are added to the end, and you can't change the field names of existing columns). However, by exporting the table and data to an OpenOffice.org Calc spreadsheet, you can rearrange and edit column names, then reimport as a new table.

To export a table, you will actually be importing it into OpenOffice Calc (or Writer).
  1. From Calc, select the View menu, Data Sources.
  2. From the databases shown, select your database, then your table. It will appear in datasheet format.
  3. Click on the upper-left corner box to select the entire table and drag it into cell A1 of your spreadsheet. (Now, if you just want to export it, you may save it in any format Calc supports.)
  4. Rearrange/edit your column names as desired.
  5. Select the upper-left corner box to select the entire sheet, then copy it.
  6. From the Base main window, paste the table.
  7. In the dialog which appears, give the table a new name, select Definition and Data, Next, move all columns over, Next, adjust field types as needed.
  8. Click Create; when prompted, do not create a primary key.
  9. Edit the new table, and set the primary key field(s).
Depending on the complexity of the table and your skill level, you may find it easier just to create a new table, then append the old data into the new table (using a SQL INSERT INTO query).