• Skip to main content
  • Skip to primary sidebar
  • Home
  • Blog
  • VBA Programming
  • Open-Libre Office
  • Web Stuff
  • Videos
    • VBA Articles
    • LibreOffice And Open Office
  • Excel VBA Glossary
  • About
  • Contact

My Best Stuff Is In The Newsletter

No charge. No spam. Unsubscribe anytime.

Submitting...

Export Table Data From Libre Office Base

In this tutorial we are going to export the contents of the table below to a text file in csv (comma seperated values) format.

LibreOffice Base is the free database application that is packaged with LibreOffice, I use it all the time and in my opinion is the only option for quick and dirty database analysis on the Apple Mac platform (which i use).

LibreOffice base is also available on Mac, Pc and Linux.

Yes you can use Filemaker but that is more of a rapid application development tool than a database for crunching data.

Check out the detailed video tutorial below and then read through the summary for your reference.

Get notified when new Business Programmer blog or video tutorials are created.

Submitting…

So we are going to export the content of a table called "tblKeywords" pictured below.

Exporting the contents of the above table could then become part of an automated process to regularly share data with other applications.

First create a "text" table in LibreOffice Base using SQL

A text table is a special type of table that has similar characteristics to a normal table other than it’s purpose is to link to an external text file.

This text "table" can then be linked against existing files, or can in fact create files, these files will have their contents modified when you change the contents of the text table using sql for example.

In order to export the table pictured above to the file system we will first create a corresponding "text" table with the create table query below.

create text table "tblExportKeywords" (ID integer, "Seed_ID" integer,
"Keyword" varchar(255), "Currency" varchar(4), "MonthlySearches" double,
"Competition" double, "ShortList" Boolean, "TempID" integer)

Note that LibreOffice Base uses the HSQLDB database engine, the default state of it’s sql engine is to assume that all object names (fields, tables etc) are uppercase, items that are not uppercase need to be enclosed in quotes.

Then Link Text Table To Output CSV File.

We then need to "link" this file to a text file on your file system, this file if it does not already exist will be created in the "database" folder of your base install if you are using the recommended "split database" format.

set table "tblExportKeywords" source "tblKeywords.csv;encoding=UTF-8"

The sql above links the table "tblExportKeywords" to a text file called "tblKeywords.csv" with a file encoding of "UTF8"

If "tblKeywords.csv" does not already exist it will be created when the above query is run.

Finally Export Your Data To The Text File

All that remains is to export the base table data to your text file, this is accomplished by running an insert query from your regular table to the text table (in this instance tblExportKeywords).

insert into "tblExportKeywords" select * from "tblKeywords"

LibreOffice Base will look after the details of writing this to the text file as a result of executing this process.

Your exported text file (highlighted) has now been created in the database folder of your base split database, you can use a base macro or python code to move it elsewhere as part of a larger application, or just manually move the file yourself for import into another application.

Get notified when new Business Programmer blog or video tutorials are created.

Submitting…

Don’t forget to comment below and let me know if this was helpful.

Also feel free to tell me what topics you would like covered in the future.

Filed Under: Open-Libre Office Tagged With: LibreOffice OpenOffice

Reader Interactions

Comments

  1. dan says

    25/02/2020 at 07:48

    Hello!

    Very thankfull for you solution, which was my first step. Later one i found a faster one (in terms of typing). Maybe you are interested in it:
    https://forum.openoffice.org/en/forum/viewtopic.php?f=13&t=5009#p23249

    greets and thanks for your great explanation

    Dan

    Reply
  2. Jean Druck says

    12/08/2020 at 15:01

    Hi, I have used your procedure to export a table to a CSV as shown in your video. Great, it works perfect. Now I have a problem to change the delimiter from comma(,) to TAB (\t). I tried different code next to “encoding=UTF-8;delimiter=\t” … but without success. Do you have an idea ?

    Thanks

    Reply
    • Jean Druck says

      12/08/2020 at 15:19

      Ok, ok, I found it in the meantime: Example:
      Create text table “AGIPA.txt” (“Titre du Livre” varchar(255), “BARCODE” Char(20), “Codex” Char(20));
      set table “AGIPA.txt” SOURCE “AGIPA.txt;encoding=UTF-8;fs=\t;vs=\t;lvs=\t)”;
      insert into “AGIPA.txt” select “Titre du Livre”, “BARCODE”, ” as “Codex” from “Livres” where “Etiquette Livre” = True;
      DROP TABLE “AGIPA.txt”;

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Free Training Videos

Make VBA Listbox Work as Database Grid

Image

Ulitmate Excel VBA Advanced Filter Tutorial

Click video and press f for full screen or watch on YouTube

Dynamically Link Images to LibreOffice Base Form

Click video and press f for full screen or watch on YouTube

Create Database with LibreOffice Base

Click video and press f for full screen or watch on YouTube

Create VBA Form In Excel

Click video and press f for full screen or watch on YouTube

Affiliate Disclamer

We hope you love the products we recommend! Just so you know, we may collect a share of sales or other compensation from the links on this page.
Thank you if you use our links, we really appreciate it!

Terms Of Service | Privacy Statement | Copyright © 2024 BusinessProgrammer.com.