Writer’s mail merge provides features to create and print multiple copies of one item (such as return address labels, promotional stickers, or t-shirt transfers) or to produce copies that include variable information (for example names, addresses, and amounts due):
Form letters (a document to send to a list of recipients)
Mailing labels, labels for physical file folders, and similar purposes
Variable data is typically derived from a data source, as discussed below. If all output is to be the same (for example, return address labels), the merge can use manually entered text or images.
This chapter describes the mail merge process. The steps include:
1) Create and register a data source.
2) Create and print form letters, mailing labels, and envelopes.
3) Optionally, save the output in an editable file instead of printing it directly.
An address data source is a database containing the name and address records from which mailing labels and envelopes can be derived. LibreOffice can create the database from spreadsheets, text files including Writer documents, and databases such as MySQL. 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 to a comma-separated values (CSV) file.
For a data source to be directly accessible from within a Writer document, it must be registered. You need to do this only once.
2) The choices on the first page of the wizard (Figure 1) vary with your operating system. Select the appropriate type of external address book. For a spreadsheet, it is Other external data source. Depending on your choice, the list of steps on the left may change. Click Next.
3) On the next page of the Wizard (Figure 2), click on the Settings button.
4) On the Create Address Data Source page (Figure 3), select the Database type. In our example, it is Spreadsheet. Click Next.
5) On the next page (Figure 4), click Browse and navigate to the spreadsheet that contains the address information. Select the spreadsheet and click Open to return to this dialog.
6) To test that the connection has been correctly established, click the Test Connection button in the lower right of the dialog (not shown in Figure 4). You should get the message The connection was established successfully; otherwise, you will get an error message.
7) Click Finish.
8) On the next page (Figure 5), click Next. You do not need to click the Field Assignment button. (When you are using the Mail Merge Wizard, you may need to do the Field Assignment step; see page below.)
9) On the Data Source Title page (Figure 6), the name and location of the new database (.odb) is shown in the Location field. You can change this name or store the database file in a different location; deselect Embed this address book definition into the current document, then click Browse to choose the location and name the file.
10) Click Finish. The data source is now registered.
You can create a form letter manually—the simplest and most comprehensive method, which is described here—or you can use the Mail Merge wizard starting below.
1) Create a new Writer document (File > New > Text Document) or open an existing form letter with File > Open.
2) Display the registered data sources: View > Data Sources (or press Shift+Ctrl+F4).
3) Find the data source that you wish to use for the form letter, in this case Addresses. Expand this folder and the Tables folder, and select Sheet1. The address data file is displayed.
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.
5) Our example database (Figure 7) contains a field for a second address line (AD2) that is blank for some addresses. If you wish to remove any blank lines that may appear in the address block when the letters are printed, you can use the procedure described in “Suppressing blank lines (optional)” below. Otherwise, continue to the next step.
a) Choose File > Print and click Yes in the message box.
b) In the Mail Merge dialog (Figure 10), in the Records section, you can choose to print all records or selected records. To select individual records to be printed, Ctrl+click on each one. 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. You can also specify a range of record numbers to print.
c) To send the letters directly to the printer, select Printer in the Output section and click OK. Or, you can save the letters to a file for further editing or formatting; see “Saving 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 and is highly recommended.
If you wish to suppress blank lines, follow this procedure:
1) Click at the end of a paragraph to be suppressed if empty, and then choose Insert > Field > More Fields to display the Fields dialog.
2) Select the Functions tab and then choose Hidden Paragraph in the Type column.
When using the Mail Merge Wizard (page below), you can select automatic suppression of blank lines and avoid the work described in this step.
3) 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:
For example, in our database the condition to test if the AD2 field is empty would be:
![Addresses.Sheet1.AD2] as illustrated in Figure 11.
Alternative ways to express this condition include NOT Addresses.Sheet1.AD2 and Addresses.Sheet1.AD2 EQ “”.
4) Click Insert.
You may prefer to save the letters in a file, to allow for proofreading or formatting. To do this:
2) You can choose whether to save the output as a single document (containing all of the letters) or save the letters as individual documents; and you can specify the name, location, and format of the files.
3) Click OK. In the Save as dialog, 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.
You can now open the letters and edit them individually as you would edit any other document.
Labels are commonly used for printing address lists (where each label shows a different address), but they can also be used for making multiple copies of one label only, for example return-address stickers, or labels for CDs/DVDs or other items.
If you are printing the same information on each label, you may find the Business Cards dialog useful. Access it through File > New > Business Cards. The Labels and Business Cards dialogs are very similar.
1) Choose File > New > Labels. The Labels dialog opens.
2) On the Labels page (Figure 13), select the Database and Table.
3) From the Database field drop-down list, select the first field to be used in the label (in this example, FNAME), then click the left arrow button to move it to the Label text area.
4) Continue adding fields and inserting desired punctuation, spaces, and line (paragraph) ends until the label is composed. Figure 13 shows the completed label.
On some operating systems, a scroll bar will appear below the Label text box and you can see where the paragraph ends are located. On others (as in the example), the fields may appear in a list and you cannot see where the paragraph ends are located. You can check them later in the procedure (Step ).
5) Select the label stock in the Brand drop-down list. The types for that brand then appear in the Type drop-down list. Select the size and type of labels required, and then go to Step . If your label sheets are not listed, go to Step .
a) Select [User] in the Type box on the Labels page. Then, click the Format page of the Labels dialog (Figure 14). Measure on your labels those dimensions illustrated and enter them into the respective boxes on the left side.
b) You can now save the label template if you are likely to use it again. Click Save.
c) In the Save Label Format dialog that pops up, type names for your label Brand and Type. Click OK.
7) On the Options tab of the Labels dialog (Figure 15), select the Synchronize contents option.
8) Click New Document. You now have a one‑page document containing a series of frames, one for each label of the selected type and filled with the data source address fields that you selected. Although this document appears to have only one page of labels, the printed or saved output will be expanded to include enough pages for all of the selected records from the data source.
9) In this document you can see the paragraph ends if you use the Toggle Formatting Marks toolbar button or View > Formatting Marks on the Menu bar.
10) You should also see a small window containing a Synchronize Labels button, usually in the upper left corner of the screen.
11) If any paragraph ends or other punctuation are missing, or if you wish to change the font or other characteristics of one or more fields or lines (paragraphs) of all the labels, you can do so now. In the upper left label, select the field(s) that you wish to change, then change them manually or by selecting a paragraph style or character style. Add any missing punctuation. Then click the Synchronize Labels button to automatically add these changes to all of the labels.
1) Choose File > Print. The message shown in Figure 9 appears. Click Yes to print.
2) In the Mail Merge dialog (Figure 10), 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.
3) Click OK to send the labels directly to the printer. If you prefer to save the labels to a file, then select File in the Output section, where Save as single document is preselected. In this case, clicking OK opens the Save As dialog, where you can enter a file name and location, as described in Step above.
Blank lines in addresses on labels are suppressed automatically, as they are when using the Mail Merge Wizard (page below).
To edit a saved file of mailing labels, open the file in the same way as any other Writer document.
You can edit individual records manually (for example, to correct a spelling error without needing to change the source spreadsheet and regenerate the labels), but you cannot edit all labels at once (for example, to change the font used) by a manual technique. However, you can edit the paragraph and/or character styles associated with the label records:
1) Right-click in a label record. Choose Paragraph > Edit Style in the context menu.
2) Then in the Paragraph Style dialog, you can make changes to the font name, the font size, the indents, and other attributes.
Instead of printing mailing labels, you may wish to print directly onto envelopes.
The production of envelopes involves two steps, setup and printing. For general instructions on setting up envelopes for printing using the Format and Printer pages of the Envelope dialog, see “Printing envelopes” in Chapter 7, Printing, Exporting, Emailing, and Signing.
To produce a single envelope, you can type or paste the name and address into the Addressee box, or you can get information from an address data source as described in this section.
1) Choose Insert > Envelope on the Menu bar.
2) On the Envelope tab of the Envelope dialog (Figure 20), choose whether to add Sender information (the “from” address) to the envelope. If so, type the information in the Sender box. If you’re using envelopes preprinted with sender information, either leave this box empty or deselect the Sender checkbox.
3) Create the Addressee fields by dragging and dropping from the data source headings, as described in “Printing mailing labels” above, then click the New Document button to create the envelope template.
4) At this point you may wish to save this document as a template.
1) Choose File > Print. The message shown in Figure 9 appears. Click Yes to print.
2) The Mail Merge dialog (Figure 10) 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. To check the envelopes before printing them, see “Saving merged documents” above for instructions. Blank lines are automatically suppressed.
The Mail Merge Wizard (Figure 17) gives several options for the starting document:
Use the current document
Create a new document
Start from existing document
Start from a template
Start from a recently saved starting document
For the purposes of this example, we opened a new text document.
Select Use the current document and click Next.
Figure 17: Select starting document
The wizard can produce letters or email messages. In this example, we are producing a letter. Select Letter and click Next.
This is the most complex step in the wizard. In this step (Figure 19) you will do three things:
1) Tell the wizard which data source to use. The data source must be an existing file.
2) 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.
3) 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. This is described in “Matching the fields” below.
Figure 19: Insert address block
1) If the current address list, identified beneath the Select Different Address List button in section 1 (Figure 19), is not the one you wish to use, click the button to open the Select Address List dialog (Figure 20) for choosing a data source.
Figure 20: Select address list dialog
2) Select the address list and click OK to return to the Insert Address Block dialog. We retain Addresses as our address book for this example. The wizard can also exclude certain records; click Filter to choose them.
1) In section 2 (Figure 19), 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 for more choices.
2) The Select Address Block dialog (Figure 21) 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 section. 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 Edit Address Block dialog.
3) In the Edit Address Block dialog (Figure 22), you can add or delete address elements using the arrow buttons between the boxes. To move elements around, use the arrow buttons on the right. For example, to add an extra space between the first and the last names in Figure 22, click <Last Name> and then click the Move right arrow button on the right-hand side.
Figure 21: Select address block
Figure 22: Edit address block
4) Click OK to close the Edit Address Block dialog, then click OK on the Select Address Block dialog to save your changes and return to the Mail Merge Wizard.
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 19 on page Figure 19). The box at the bottom displays one record at a time, using the address block format you specified. 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.
2) If the addresses do not display correctly, click Match Fields.
Address elements are the terms the wizard uses for each field, such as <First Name> and <Last Name>.
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.
3) When you have matched all the fields, click OK to return to the Insert Address Block dialog. 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 the next step.
Figure 23: Match fields dialog
4) Notice the option for Suppress lines with empty fields in section 2 of Figure 19. Using the Wizard, you do not have to create your own conditional suppression fields, as you do when using the manual form letter method described earlier in this chapter..
It is possible to create just about any salutation you want in this step (see Figure 24).
Select This document should contain a salutation to enable the General salutation list box. Some general texts are available in the list box, or you can enter your own text. A preview pane displays your choice.
Select Insert personalized salutation to enable further salutation constructs.
You can, for example, 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. In a spreadsheet, you might have a column called Gender. In the section Address list field indicating a female recipient, set the Field name to Gender and the Field value to F. The Male salutation is then printed for all men and the Female salutation for all women. Unfortunately, LibreOffice does not provide for other genders; however, you can use a non-gendered salutation.
If you do not have such a column in your spreadsheet, or if you do not need to distinguish between genders in the salutation, then you can leave the Field name and Field value boxes empty and use the customized content of the Male list box for the salutation to all recipients.
Figure 24: Create a salutation
As an example:
1) Click the New button alongside the Male list box. The Custom Salutation (Male Recipients) dialog opens (see Figure 25).
2) Select Salutation in the Salutation elements list on the right and drag it into box 1 on the right.
3) In the Customize salutation box, select an appropriate greeting or type your own text into the box. Edit it as needed.
4) Select and move First Name from the Salutation elements list into box 1, using either the Add to salutation arrow button or by dragging it. Then click the Move right arrow button on the right-hand side to add space between the salutation and the first name.
5) Select and move Last Name from the Salutation elements list into box 1, then click the Move right arrow button to add space between the first and the last names.
6) Finally, move Punctuation Mark across and select the comma from the choices in the Customize salutation box.
7) The construct is shown in the Preview box.
8) Carry out any final editing. Click OK.
This method allows you to use gender neutral titles such as Doctor (Dr) and Reverend (Rev), or titles such as Ms, or omit titles.
Figure 25: Customizing the salutation
In Step 5: Adjust layout, 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 26 to move the elements.
Figure 26: Adjust layout
You now have a Writer document into which you can type the contents of the letter. To merge the fields and print the letters, choose File > Print on the Menu bar. A message pops up, asking if you want to print a form letter. Click Yes.
The Mail Merge dialog (Figure 10) is now displayed, where you can optionally select records to include or exclude (in the top section) and, in the Output section, choose to print the letters immediately (Printer) or save them (File) for further editing or printing at a later time.
If you choose File, you can then choose whether to save the output as a single document (containing all of the letters) or save the letters as individual documents, and you can specify the name, location, and format of the files. Click OK to save the letters. You can now open the letters and edit them individually as you would edit any other document.