2. What is Mail Merge.
Creating/registering data source.
Creating a form letter.
Printing mailing labels and envelopes
Using the Mail Merge Wizard.
3. LibreOffice Writer provides very useful features to create and
print:
• Multiple copies of a document to send to a list of different
recipients (form letters)
• Mailing labels
• Envelopes
All these facilities, though different in application, are based
around the concept of a registered data source, from which is
derived the variable address information necessary to their
function.
This chapter describes the entire process. The steps include:
1. How to create and register a data source.
2. How to create and print form letters, mailing labels, and
envelopes.
3. Optionally, how to save the output in an editable file instead
of printing it directly.
4. A data source is a database containing the name and address records
(and optionally other information) from which a mailing list may be
derived. Although you can create and print mailing labels and envelopes
without using a data source, in most cases using one is the best
approach. This chapter assumes that you are using a data source.
LibreOffice can access a wide variety of data sources, including
spreadsheets, text files and databases such as MySQL, Adabas, and
ODBC. If the information to be used in the mail merge is currently in a
format that LibreOffice cannot access directly, you need to convert it, for
example by exporting it to a comma-separated values (CSV) file.
For the following example we use a spreadsheet with the following
column (field) headers: Last name, First name, Phone Number,
Address, City, State, Postal Code, Department, Group. A sample data
source is shown in Figure 1.
6. For a data source to be directly accessible from within a Writer
document, it must first be registered as described below. You only need
to do this once; after that, the data source is available to all documents
in LibreOffice.
1) From within any Writer document, or from the LibreOffice Start
Center, choose File > Wizards > Address Data Source.
2) The choices on the first page of the wizard vary with your operating
system. Select the appropriate type of external address book. In this
example, it is Other external data source. Click Next.
8. 3) On the next page of the Wizard, click the > Settings button.
Figure 3: Starting the Settings part
of the Wizard
9. 4) In the Data Source Properties page, select the Database type. In
our example, it is Spreadsheet. Click Next.
Figure 4: Selecting the database type
10. 5) In the next dialog box, click Browse and navigate to the
spreadsheet that contains the address information. Select the
spreadsheet and click Open to return to this dialog box. At this
time you may wish to test that the connection has been correctly
established by clicking on the Test Connection button (not shown
in illustration).
6) Click Finish.
Figure 5: Selecting the spreadsheet document
11. 7) On the following page, click Next. Because this is a spreadsheet,
do not click Field Assignment.
Figure 6: Because this is a spreadsheet, do not
click Field Assignment
12. 8) Name the file in the Location field. The default is
...Addresses.odb; but you may replace Addresses with another
name if you wish. You may also change the name in the “Address
book name” field. In our example, the name “TEC Services” was
used for both.
9) Click Finish. The data source is now registered.
Figure 7: Name the .odb file and the address
book
13. You can create a form letter manually, which is the simplest and most
comprehensive method and is described here, or you can use the Mail Merge wizard
as described in “Using the Mail Merge Wizard to create a form letter”. If you elect to
use the wizard, pay close attention to its current limitations, as identified within its
description.
1) Create a new text document: File > New > Text Document, or open a pre-
existing form letter with File > Open.
2) Display the registered data sources: View > Data sources (or press F4).
3) Find the data source that you wish to use for the form letter, in this case TEC
Services. Expand the TEC Services and Tables folders, and select Sheet1. The
address data file is displayed.
15. 4) Now create or modify the form letter by typing in the text,
punctuation, line breaks, and so on that will be present in all of the
letters.
To add the mail-merge fields where needed (such as names and
addresses), click in the field heading and drag it to the appropriate
point in the letter.
Note that address lines should be in individual paragraphs, not
separated by line breaks it as might seem preferable. The reason
for this will be made clear in the next step.
17. 5) Continue until you have composed the entire document. At this
time you may wish to consider suppressing any blank lines that
may appear in the resulting letters. If not, skip ahead to Step 7.
Figure 10: The completed form letter
18. 6) To suppress blank lines:
a. Click at the end of the first paragraph to be suppressed and then choose Insert >
Fields > Other.
b. Select the Functions tab and then click on Hidden Paragraph in the Type column.
c. Now click in the Condition box and enter the details of the condition that defines
a blank address field. It has the general form of:
![Database.Table.Database field]
where the ‘!’ (NOT) character indicates the negative case and the square
brackets indicate the condition.
For example, in our TEC Services database the condition to test if the Company
field is empty would be:
![TECServices.Sheet1.Last Name] as illustrated in Figure 11.
To test for multiple conditions use the operators AND and/or OR between the
conditional statements, for example:
![TECServices.Sheet1.Group]AND![TECServices.Sheet1.Last Name]
d. Click Insert, but do not close the dialog box until you have amended all the lines
that should be suppressed.
20. 7) The document is now ready to be printed.
a) Choose File > Print and respond with Yes in the message box.
Figure 12: Mail merge confirmation message
21. b) In the Mail Merge dialog box (Figure 13), you can choose to print all
records or selected records. To select records to be printed, use
Ctrl+click to select individual records. To select a block of records,
select the first record in the block, scroll to the last record in the
block, and Shift+click on the last record.
c) Click OK to send the letters directly to the printer. Or, you can save
the letters to a file for further editing or formatting; see “Editing
merged documents” below.
d) If you have not saved the original, prototype form letter document
(template) previously, then you should do so now. Having a form
letter template could greatly simplify the creation of other form letters
in the future and is highly recommended.
23. You may prefer to save the letters to a file, to allow for proofreading or some later
formatting. To do this:
1. In the Mail Merge dialog box (Figure 13), select File in the output section,
instead of using the default Printer selection.
2. This changes the dialog box to display the Save merged document section,
where Save as single document is pre-selected. You can choose to save each
letter as an individual document instead.
3. Click OK. In the Save as dialog box, enter a file name for the saved letters and
choose a folder in which to save them. The letters will be saved consecutively as
separate pages in the single document, or numbered consecutively in individual
files if saved as single documents.
You can now open the letters and edit them individually as you would edit any other
document.
24. Before beginning this process, note the brand and type of labels you intend to
use.
Preparing for printing
To prepare mailing labels for printing:
1) Choose File > New > Labels.
2) On the Options tab, ensure that the Synchronize contents option is
selected.
3) On the Labels tab (Figure 16), select the Database and Table. Select the
Brand of labels to be used, and then select the Type of label.
4) If you are unable to identify your label product in the list, then you can
define the labels you have. Click on the Format tab of the Labels dialog
box. Set values for the columns and rows first. Take a ruler and measure
on your labels, those dimensions illustrated in the window of the graphic,
and enter them into the respective boxes on the left side.
26. 5) You can now save your label template if you are likely to use it
again. Click Save.
6) In the box that opens, enter names for your label Brand and
Type.
Figure 15: Name and save the label.
27. 7) Click the Labels tab.
Figure 16: Select Database, Table, label Brand, and
label Type
28. 8) Click the drop-down arrow under Database field. Select the first
field to be used in the label (in this example, Title). Click the left
arrow button to move this field to the Label text area, as shown in
Figure 17.
Figure 17: Move fields from Database field list to Label
text area
29. 9) Continue adding fields and inserting desired punctuation, spaces,
and line breaks until the label is composed. (Figure 18) shows the
completed label.
Figure 18: The completed label
30. Instead of printing mailing labels, you may wish to print directly
onto envelopes. There are two basic ways to create envelopes,
one where the envelope is embedded within a letter, generally as
the first page (Insert in the Envelope dialog box), and another
where the envelope is an independent document (New Doc. in
the dialog box). In each case the addressing data may be
manually entered, for example by copying and pasting from the
letter with which it is associated, or it may originate within an
address data source.
This section assumes the use of an address data source and, for
convenience, a free-standing envelope. The production of
envelopes involves two steps, setup and printing.
31. 1) Choose Insert > Envelope from the menu bar.
2) In the Envelope dialog box, select the Format tab (Figure 19),
where you can select the envelope format to use. You can then
arrange the layout of the envelope to suit your requirements,
together with the character and paragraph attributes to be used in
the Sender and Addressee areas. These attributes are accessed
using the Edit buttons to the right of the dialog box, next to the
word Format.
Note:
If the list of envelope formats in the Size section of this dialog box does not
include the size you need, choose User Defined (at the bottom of the list) and
specify the envelope size using the Width and Height boxes.
Tip:
At this stage it is only possible to vary the position of the origin points (upper left
corners) of the frames that will hold the Sender and Addressee information, but once
the envelope has been created full adjustment of size and position will become
possible and you may wish to make some cosmetic adjustments.
33. 3) The next step is to select the Printer tab (Figure 20), from
where you may choose the printer you intend to use, its
setup—for example, specification of the tray holding
envelopes—and other printer-related options such as envelope
orientation and shifting. You may need to experiment with
these settings to achieve the best results with your printer.
Figure 20: Choosing printer options for an envelope
34. 4) Select the Envelope tab (Figure 21).
Figure 21: Choosing addressee and sender information for
envelopes
35. 5) Choose whether or not to add Sender information to the envelope by selecting or
deselecting the Sender option. If wanted, edit the information in the Sender box
(Sender is the “from” on the envelope).
6) You now have the choice of creating the Addressee fields by dragging and
dropping from the data source headings (as described in “Creating a form letter”
on page 7, and in particular in Figure 9) or using the facilities of the Envelope
tab.
If you prefer dragging and dropping, then click New Doc., drag your data source
headings into the Addressee area on your new envelope and skip to step 10),
otherwise continue with the next step.
7) Verify, add, or edit the information in the Addressee box. You can use the right-
hand drop-down lists to select the database and table from which you can
access the Addressee information, in a similar fashion to that described for
“Printing mailing labels”, paragraphs 3, 4 and 5. The similarity of the method with
Figure 17 and Figure 18 will be clear.
8) When you have finished formatting, click either the New Doc. or Insert button to
finish. As might be expected, New Doc creates only the envelope template in a
new document, whereas Insert inserts the envelope into your current document
as page 1.
If you don’t want to proceed with this envelope, click Cancel or press the Esc
key. You can also click Reset to remove your changes and return to the original
settings extant when the dialog box opened.
36. To merge addresses and print the envelopes:
1) Choose File > Print. A message box (Figure 12) appears. Click
Yes to print a form letter.
2) The Mail Merge dialog box (Figure 13) appears. As with form letters
and mailing labels, you can choose to print envelopes for one,
several or all address records in the database.
3) Make your selections and then click OK to print direct to the printer.
37. Before starting you should note the following limitations:
In Step 4 creating the salutation only allows the sex-related Mr. and
Mrs. It makes no allowance for Miss or Ms., nor does it permit
sexless addressing such as Dr.
Again in Step 4, the General salutation is not editable and the default
values are somewhat limited.
In Step 5 the layout is idiosyncratic, with paragraph marks all over
the place so as to space the address block frame and salutation.
Creating a professional looking document requires significant editing.
If the above limitations are not a hindrance to you, then open a new
document with File > New > Text Document and start the Mail Merge
wizard using Tools > Mail Merge Wizard. The wizard opens, as shown
in Figure 22.
38. The wizard gives various options to select your starting document:
• Use the current document.
• Create a new document.
• Start with an existing document.
• Start from a template.
For the purposes of this description, we assume that you opened a new
text document. This will ensure that all the steps in the wizard are fully
explored.
Select Use the current document and click Next.
40. The wizard can produce letters or, if a Java Mail connection exists,
email messages. In this example, we are producing a letter. Select
Letter and click Next.
41. This is the most complex step in the wizard. In this step (Figure 24) you
will do three things:
Tell the wizard which data source to use. The data source must be an
existing file; in this example it is the “TEC Services” spreadsheet
created earlier.
Select the address block to use in the document. This means choosing
which fields appear (for example, whether the country is included) and
how they look.
Make sure that the fields all match correctly. This is very important. For
example, the UK English version of the wizard has a field called
<Surname>. If your spreadsheet has a column called “Last Name”, you
need to tell the wizard that <Surname> and “Last Name” are
equivalent.
43. 1) If the current address list, identified beneath the
Select Different Address List button in section 1, is
not the one you wish to use, click the button to open the
Select Address List dialog box (Figure 25) for choosing
a data source.
45. 2) If you have not already created the address list, you may click
Create to do so now. This step will allow you to create a CSV
(Comma Separated Values) file with a new list of address records.
If you have an address list that is not registered in LibreOffice, but
which you wish to use, click Add and select the file from the
location in which it is saved.
In each of the above cases a new data source will be created and
registered.
3) Select the address list and click OK to return to step 3 of the
wizard. We retain “Points” as our address book for this example.
The wizard can also exclude certain records; click Filter to choose
them.
46. 1) In section 2 (shown in Figure 24), select the
address block to appear on the letter, define its
appearance, and choose the fields it contains.
The main page gives two choices. Click More
to open the Select Address Block dialog box for
more choices.
48. 2) The Select Address Block dialog box displays the original two
blocks plus other choices for the format of the address block (you
may need to scroll down to see all of the choices). You can also
optionally include or exclude the country (for example, only include
the country if it is not England) in the Address block settings. The
formats provided are relatively common, but they might not exactly
match your preference. If this is the case, select the address block
that is closest to what you want and click Edit, which opens the
New Address Block dialog box.
3) In the New Address Block dialog box, you can add or delete
address elements using the arrow buttons on the left. To move
elements around, use the arrow buttons on the right. For example,
to add an extra space between forename and surname in Figure
27, click <Surname> and then click the right arrow button.
50. Finally, it is time to match the wizard’s fields with the spreadsheet fields,
so that items like <Surname> and “Last Name” match correctly.
1) Look at section 3 of the wizard (shown in Figure 24). The box at
the bottom displays one record at a time, using the address block
format you selected. Use the right and left arrow buttons below that
address box to step through the addresses, checking that they
display correctly. Do not assume that all the records display
correctly, just because one or two do. Check them all if you can, or
at least a good proportion.
2) If the addresses do not display correctly (and they probably will not
right away), click Match Fields.
51. 3) The Match Fields dialog box (Figure 28) has three columns:
• Address Elements are the terms the wizard uses for each field, such as
<Forename> and <Surname>.
• Use the Matches to Field column to select, for each address element, the
field from your data source that matches it.
• The Preview column shows what will be shown for this field from the
selected address block, so you can double-check that the match is
correct.
4) When you have matched all the fields, click OK to return to step 3 of the
wizard. Now, when you use the arrow buttons to look at all the addresses, they
should all look correct. If not, go back and change anything you’re not happy
with, before clicking Next to move to step 4.
Note that you will not be able to continue until you have correctly matched all
the fields in your chosen address block. If you see <not yet matched> in a field
position it indicates that the field in question is not correctly matched.
5) Notice the option for Suppress lines with empty fields in section 2 of Figure
24. Using the Wizard, you do not have to create your own conditional
suppression fields.
53. The salutation is the initial greeting, for example, Dear Mr.
Jones. In step 4, select the salutation that will appear in the
letter.
You can use a different greeting for men and women. To do this,
Writer must have some way of knowing whether a person is
male or female.
Note: You do not need to tell LibreOffice who is a male, because it
assumes that all non-female records are males.
54. If you do not select Insert Personalized Salutation, you can use a
more general salutation without referring to the recipient directly, such
as To whom it may concern.
As in step 3, step 4 of the wizard has a preview pane at the bottom.
You should check more than one record to ensure that other records
look the way you expect.
56. In step 5, you can adjust the position of the address block and
salutation on the page. You can place the address block anywhere
on the page. The salutation is always on the left, but you can move it
up and down the page. Use the buttons shown in Figure 30 to move
the elements.
58. In step 6 you have another opportunity to exclude particular recipients
from the mail merge, as shown in Figure 31.
Figure 31: Edit
document
59. You can also edit the body of the document. If you started with a blank
document, you can write the whole letter in this step. Click Edit
Document to shrink the wizard to a small window (Figure 32) so you
can easily edit the letter.
Figure 32: Minimized mail merge wizard
60. You need to perform another important task in this step. The wizard only inserts
information from the name and address fields, but you may wish to add
additional data. In our example, we want to tell each person how many points
they had accumulated during the year; that information is in the spreadsheet.
To do this:
1) Click Edit Document in step 6 of the wizard.
2) Choose Insert > Fields > Other. The Fields dialog box opens.
3) Click the Database tab.
4) On the left hand side, select Mail merge fields.
5) Under Database selection find your data source (in this example, it is a
spreadsheet). Expand it to see the fields.
6) Click the field you want to insert, then click Insert to insert the field.
7) You can insert any number of fields any number of times into your mail
merge document.
8) Click Close when you are done.
62. This step creates all your letters, one per recipient.
Clicking the Edit individual Document button here is
similar to step 6. The difference is that you now edit a long
file containing all of the letters, so you can make changes
to a particular letter to one person. In this step of the Mail
Merge wizard, click Find to open a dialog box that allows
searches within the document, perhaps for an individual
addressee.
64. You have now completed the mail merge process. The last step is to
do something with it. In step 8, you can save the original sample
letter, save the merged document, print the letters right away or, if
you created email messages, send them.
You probably want to save the starting (prototype) document and the
merged document. To do this, select Save starting document to
reveal the Save starting document section containing the
Save starting document button. This button will be active only if the
document has not already been saved. Clicking on this button brings
up the standard Save as dialog box. Once you have named and
saved the document you return to the Step 8 dialog box as shown in
Figure 36.
66. The merged document can now
be saved by selecting
Save merged document. This
will reveal the
Save merged document settin
gs section, from which you can
select to save either as one
large file containing all the
individual, generated letters or
as a separate file for each letter.
Figure 36: Saving a merged document
67. When you have saved the
merged document, you can
print the final letters now or
later; and you can still
manually check and edit the
letters if necessary. If you
elect to print at this stage,
the dialog box shown in
Figure 37 appears; it should
be self-explanatory.
Figure 37: Printing the merged document