Creating a Table From a Spreadsheet

From NeoWiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 12:19, 7 August 2007 (edit)
Jgd (Talk | contribs)
(add link to Fr version + cats)
← Previous diff
Revision as of 15:39, 7 August 2007 (edit) (undo)
Valterb (Talk | contribs)
(botlangbar -> IT)
Next diff →
Line 65: Line 65:
-{{botlangbarEN|[[Fr:Créer une Table à partir d'un Classeur|Français]]}}+{{botlangbarEN|[[Fr:Créer une Table à partir d'un Classeur|Français]] [[It:Creare_una_tabella_da_un_foglio_elettronico|Italiano]]}}
[[Category:Tips and Hints]][[Category:NeoOffice]] [[Category:Tips and Hints]][[Category:NeoOffice]]

Revision as of 15:39, 7 August 2007

This article is part of the To Base and Back Again tutorial series

For the birding journal database, we need a table listing all of the birds we might see in our birding area. Creating a table from scratch would be tedious and time consuming. Fortunately, the data we need is already available if a format we can access and use. The { American Ornithologists' Union} provides their checklist of birds in the AOU area (North and Middle America) in an Excel file. This article describes how to get this data from the xls file into our Birding Journal database.


Importing Spreadsheets vs. Connecting to Spreadsheets

NeoOffice Base can use data from spreadsheets in two different ways. One option is to connect to an existing spreadsheet. This method is described in the Using a Calc spreadsheet as a data source article. When using this method, the data can only be edited within the source spreadsheet; data cannot be edited from within Base.

The other option is to import the data from the spreadsheet into the Base document. The data can then be edited in Base. (The original spreadsheet will not be altered when changes are made in Base.) In our case, we want to import the data, but first the spreadsheet needs some work.

Formatting the Spreadsheet

Before importing the data, we need to make sure that it is correctly formatted.

The first row of the data range (not necessarily of the document) should contain the field names. Any fields that must not be empty need to have data in them. In the case of the AOU list, a careful inspection will show that the Order, Family, Subfamily, and genus fields only contain data for the first record with that order, family, subfamily, or genus. In our database, this information needs to be in each record. To fix this:

Click in a cell that contains an Order (or Family, etc.) name. The cell border becomes black, and a small back square is visible in the lower right hand corner of the cell.
Drag this square downward; as you do so, a red border drags with you. Keep dragging until the border encompasses all of the empty cells, up to but not including the next cell with text in it, then release the mouse button. The empty cells with the text content of the first cell.

The order of the AOU checklist a standard order, used in birding books and checklists. To ensure that we can reproduce this order in the database, it would be wisest to add an ID field, with the first record given the number 1, the next 2, etc. To do so:

Insert a new column to the left of Column A (click on column A and then choose Columns from the Insert menu.
Type <>ID<> into the cell in new column A just to the left of the cell labeled <>order<>
Type a <>1<> into the first cell under <>ID<>:
Follow the instructions on the Selecting and Filling a Cell Range wiki page to fill the column so that each cell contains a number one greater than the one above it. (i.e. 1, 2, 3, etc.)

I also changed some of the field names, especially those that were originally just one letter; adjust these names as you see fit.

Importing the Data

We are now ready to import the data.

Select the entire range of the data, including the row with column names. The easiest way to do this is probably to click in the upper left hand cell of the range (probably the cell labeled ID), then scroll down to the last row of data and Shift-click in the far right hand cell of the range.
Copy this selected range
Open the Birder's journal database
Click on the Tables icon in the Database column on the right.
In the lower rectangular area, labled Tables, right-click or control-click in the white space. (If there is an existing table, make sure not to click on it).
In the contextual menu that comes up, choose Paste. The Copy Table window appears.
Give the table a name in the Table Name field; I chose AOU Birdlist.
Make sure the Definition and Data radio button is marked
Because we added an ID field while prepping the spreadsheet, we want to leave the Create primary key checkbox unchecked. If you were importing data that did not already include a primary key field, you would want to check this box.
Click Next
The Apply columns that appears allows you to choose which fields you want to import. In our case we want to import all of them, so you can click on the >> button.
Then click Next
The Type Formatting window appears. Highlight each field in turn in the vertical column to the left, and adjust the Field Name, Field Type, Entry Required, and Length settings as needed.
In this table, all the fields are TEXT except for the ID field, whose field type should be INTEGER.
Most of the Lengths are ok, although the Hawaii, Introduced, Accidental, and Nonbreeding could be reduced to a length of 5 or so, since the data in those columns is genrally only one character.
The ID and English Name fields should be marked for Entry Required.
Once the fields are properly defined, click on Create

Note: Make certain that all the field definitions are correct before clicking Create. Attempting to change field types, lengths, etc. later will destroy data in those fields.

A No primary key warning window will appear. Click No. We will identify the primary key in a moment.

Once the new table has appeared in the Tables Section of the document window, right-click or control-click on the new table. Select Edit from the contextual menu. The table opens in design view.

Click on the line containing the ID field. A green flippy triangle appears in the "cell" to the left of the word ID
control-click or right-click on the green triangle and choose Primary Key from the contextual menu. A key icon appears in the box
Click on the disk-drive icon in the toolbar to save your changes, then close the window.

You have successfully imported data from a spreadsheet.

Related Wiki Articles

Using a Calc spreadsheet as a data source

Related External Links

Bringing data into OpenOffice 2.0's database

An article from Solveig Haugland on importing data.

This article in other languages: Français Italiano
Personal tools