Monday, May 6, 2013

Import a CSV file into LibreOffice Base

After using Microsoft Access for many years, I decided to give LibreOffice Base a spin. One of the usual task I do with Access is to import a Comma Separated Values (CSV) file into an Access *.mdb database, where I could run some SQL queries on it. I wanted to do the same thing using Base. It turned out that I could copy and paste the CSV file via a LibreOffice Calc spreadsheet, but a better way is to simply open the CSV file directly, as shown below.

The example CSV file is shown in the screenshot below.


  1. From the Start button, select All Programs | Libre Office 4.0 | LibreOffice Base.

    The Database Wizard appears.

  2. Toggle on Connect to an existing database. Choose Text. Click Next.
  3. In the Path to text files field, click Browse. Select the folder containing the CSV file, e.g. D:\Temp\myfolder\. Click OK.


  4. If necessary, choose the CSV type e.g. Plain text files (*.txt). Choose the CSV separator formats. Click Next.


  5. Click Finish.

    The Save As dialog box appears.
  6. Type in a new file name, e.g. D:\Temp\csv.odf. Click Save.

    The database is created and the CSV file can be seen as a table.




    Note: this CSV database is read-only. 
  7. Now, create or open up an existing Base database, e.g. New database.odf in another window.


  8. Simply drag and drop the CSV table to the newly opened Base window's Tables icon or pane.

    The Copy table dialog box appears.

  9. Optional. In the Table name field, type in a new name.
  10. Click Next.

    The Apply columns appear.

  11. Click the >>.

    All the columns are moved to the right.
  12. Click Next.


  13. Optional. Type in a new field name and change the type or length if necessary.
  14. Click Create. Optional. When prompted to create a primary key, click Yes to create or No to ignore.

    The CSV file is imported into the Base database.

No comments: