Creating templates using OpenOffice.org

by Lucas Mbiwe 18. September 2009 19:10

A lot of people have asked us, if it is possible to use OpenOffice.org (OOo) to create templates that are compatible with LiveDocx. It actually is possible to do that. But because of OOo's approach to mail merge it is not as straightforward as in MS Word. OOo's mail merge philosophy needs a little getting used to. This post will help you understand this philosophy and get you started on creating templates with OOo.

Database-based mail merge

Mail merge in OpenOffice.org (OOo)—and this includes creating templates—cannot be done without first setting up a database. That database determines which mail merge fields can be contained in a template.

Luckily, we can use OOo Calc to setup the database, which makes the process almost effortless. The following image shows how to setup up a sample database using OOo Calc:  


Determining the mail merge fields for a template is as easy as setting their names as column headers. For the above sample this means, there will be the fields recipientsender available later on. Additional fields would go into the cells C1, D1 and so on. The best format to save this file is the default format, i.e. OpenDocument Spreadsheet (.ods).

Putting the database to work

Now that the "database" is in place, we can move to the actual template creation. For this step we need OOo Writer, of course, but please note that OOo Base also has to be installed, even though we won't use it directly.

To create our template we can use all of the "normal" text processing stuff. For inserting mail merge fields, however, we need to access the menu Insert → Fields → Other… or simply press Ctrl+F2 instead. In the dialog that opens we choose the Database tab. Then, we click on Browse…, navigate to the spreadsheet file we have created earlier, select it and click Open. OOo now creates a database based on the spreadsheet in the background.

Now, we select the type Mail merge fields on the left. Our database then shows up in the list as depicted below:

 

The database name is the same as the filename we have given the spreadsheet. The database tables correspond to the sheets in the spreadsheet file. Then again, the columns, read: fields, correspond to the cell contents we have inserted earlier.

We can now insert mail merge fields into our document. Of course, the fields are inserted at the current input position. So, we will be opening and closing the Fields dialog a lot.

Template specifics

There are a few things to bear in mind, when using OpenOffice.org (OOo) to  create templates:

  1. Templates must be saved as RTF 
  2. Field naming is rather special in OOo

The first one is simple. If we do not save our templates in RTF format, they will not work. It is that simple.

The second one is a bit more tricky. By choosing View → Field Names from the menu or by simply clicking Ctrl+F9 we can make the field names visible. This is quite convenient, since these will be the names we will have to use later on in our applications.


As we can see in the above image, the naming scheme is quite simple:

  • database.table.column

or from our spreadsheet perspective:

  • filename.sheet.column

There is just one big caveat. The dots in the field names are no full stop characters but ÿ characters which only look like dots in OOo. This means, we have to use the GetFieldNames() method, before we can use the fields. So, when using field names like LiveDocxÿletterÿrecipient in our code, we are able to put our templates, created in OOo, to work.

Currently rated 3.2 by 9 people

  • Currently 3.222222/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Comments

Comments are closed

Calendar

<<  May 2012  >>
MoTuWeThFrSaSu
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

View posts in large calendar

RecentPosts