Linux

Three great ways to use variables in LibreOffice and OpenOffice

Learn how to get the most out of the variables feature in both OpenOffice and LibreOffice.

When I was looking for the seven great features of OpenOffice and LibreOffice that you probably ignore, one of those features turned out to be variables. This week I'm going to give you a bit more reason to know how variables work, including the real world example that granted them a place in that list.

Three ways to use variables

Variables, or "user-defined fields", are pieces of dynamic content that our two free office suites (FOS) can generate and manage for you. Writer, the word processor of the suites, has a panel to add many variables, or create custom ones. The spreadsheet and presentation tools don't give access to the same panel because, I guess, there never was much demand for it. After all, spreadsheets have their own functions and a whole different approach to dynamic content anyway. Presentations, instead, are usually static stuff without much occasion to use variables. You may still generate whole slideshows automatically from templates, with this old trick of mine, if you really needed to, but let's look specifically at Writer.

Its predefined variables include things like dates, page numbers, authors, and file names. You can create your own variables, selecting Insert - Fields->Other->Variables, which is where things get interesting. The Variables page at LibreOffice.org is a good starting point to learn all you can about these objects. Personally, I found at least three reasons to do it. The first is the "DDE" ("Dynamic Data Exchange") type that lets you dynamically embed data from one file into another (details here).

Automatic Numbering: How (and where) you need it The second way variables can come in handy are for automatic numbering options. Our FOSs do offer, of course, auto-numbering of paragraphs, chapters and cross-references. Sometimes, however, that's not enough. What if, for example, you needed some way to insert automatically incremented numbers in random places of your document? One way to quickly do this, summarized in Figure A, consists of three steps:
  • Create a custom field (upper panel in Figure A) of the "Number Range" type, called testrange in our example.
  • Select it in the document text.
  • Click on Edit | AutoText, to associate a new AutoText shortcut (TS) to testrange (lower panel in Figure A).

Figure A

The red oval in Figure A shows the result, that is what I got, after the procedure above, when I started typing "ts", then F3, then "ts, then F3... Neat, huh? The F3 key, of course, tells OpenOffice or LibreOffice to treat as text to be replaced the last string you typed. For all the gory details, check page 8 of the "Tricks for working with fields" tutorial.

Templates that ask you for variables

A third way I like to use variables is in templates. You can create templates that prompt you to give them new values when you use them. The procedure, courtesy of OpenOffice user JohnW and tested by me in LibreOffice 3.5.7, works as follow:

  • Select "User Field" in the Variables panel.
  • Name it and click the green check mark, but don't click on Insert.
  • Click on "Input Field" in the Type box, and then insert a meaningful prompt in the Reference field ("Who's next customer?" in Figure B).
  • Now click Insert, enter some spaces just as a placeholder, and click OK.
  • Move back to "User Field" and insert the variable in any other places of your document that need it (you only want one Input Field per variable or you will be prompted for its content more that once).
From now on, whenever you'll open that file and place the cursor where you inserted your variable (Figure C):

You'll get the prompt to give it a value, and clicking on it will open the corresponding pop-up box (Figure D):

A real-world use case for variables

Steven Shelton is a lawyer whose "Resources for Attorneys" page specifically suggests some Free Software products for colleagues as great tools to "save money in your practice, or to do more with less". When I was doing research for the "Seven Features" post, Mr. Shelton wrote to me:

As an attorney, I frequently have to generate tons of documents when I initially take on a case (a retainer agreement, an appearance, discovery demands, forms for my office, letters to the client and opposing counsel, etc.) and I have them all put into a single file that uses variables to generate them all at the same time. I frequently speak with other attorneys who don't realize that by using variables, you can create these kinds of documents in five minutes or less using variables.

At this point, I may have written some more thousands words about the greatness of variables but, luckily for you, there was no need to do it. Mr. Shelton was so kind to share with all TechRepublic readers the actual template he uses for his court-appointed criminal cases (zip file, .OTT), so here's a little challenge for you: download the template, and prepare it as explained in its first page. Then share in the comments (if you used OpenOffice or LibreOffice) how long it took for you to get your fully customized version of a 38 page document!

About

Marco Fioretti is a freelance writer and teacher whose work focuses on the impact of open digital technologies on education, ethics, civil rights, and environmental issues.

0 comments