Home | Tips | Library | Other Authors | Other WP Sites | Writer's Links | Contact | Site Map | Donate |
Barry
MacDonnell's Toolbox for WordPerfect |
||
Macros, tips, and
templates for Corel®
WordPerfect® for Windows® |
Page
updated Sep 6, 2023 | |
WordPerfect
Tips Main tips page | Browse more tips |
||||||||||||||||||||||||||
Merge tips Page contents (and other resources) • Basic information and resources • Merging to subdivided pages • Sorting and/or converting existing address labels - Sort address
labels by last name (surname)
Sort address labels by ZIP code Convert (extract) existing labels to a table Convert (extract) existing labels to a merge data file (.DAT) • Converting tables to merge data files (.DAT) or plain text • Converting merge data files (.DAT) to WordPerfect tables for sorting/merging; merging data files into a table; and converting data files to "comma-separated values" (.CSV) files [to do the opposite (i.e., .CSV to .DAT) see the resources section of this sidebar below] • Converting merge files (i.e., form documents and data files) to regular WordPerfect documents: See the program's Help (F1) and Search for "Converting merge files" (see the "To convert a form document or data file..." link on that dialog page) • Extract table cell data that is not in merge format so it can be used as a merge data file (i.e., cells containing lines of data that should be in separate columns [cells], not all in a single column) • How to edit just one field in several records of a merge data file • Workarounds for disappearing bookmarks in merges • Automatically number table rows (or items) when you merge into a table • Merge tips for multi-page documents - includes: ◦ setting up
different printer trays for the first (usually: letterhead) page and
subsequent pages (see also next link below for more details);
◦ resetting page margins and page numbering for each merged document; and ◦ forcing each multi-page merged documents to start numbering with page "1". • Using a keyboard merge • Converting text to a table -- and converting a table to text or to a merge data file. • Converting merge codes to text - an external link to a thread on WordPerfect universe; the macro there is useful to display or print a form file and its merge codes in plain text (Note: to convert regular format codes (bold, italics, etc.) to text equivalents see Codes2Txt) • To convert data in .CSV (Comma Separate Values) format (e.g., exported from some email programs) to a WordPerfect .DAT file, see the Corel shipping macro, CSVtoMerge,wcm, included in WordPerfect X7 and later versions. • More tips on using tables: see here. • Merge tips for multi-page documents - includes: ◦ setting up
different printer trays for the first (usually: letterhead) page and
subsequent pages (see also next link below for more details);
◦ resetting page margins and page numbering for each merged document; and ◦ forcing each multi-page merged documents to start numbering with page "1". |
■ Basic merge information and some resources Online (peer) support The Macros & Merges Forum at WordPerfect Universe can help you find answers to many of your merge questions. (Free to join.) Tutorials, tips, and some other resources [in no particular order:] • Setting Up a Mail Merge, a Corel tutorial by Laura Acklen. Topics: Building the data file; setting up the form file; merging the files; creating envelopes during a merge. Basic information, but useful for newcomers. • Performing merges (a more comprehensive reference): See the WordPerfect User Guide accessed from the program's Help (menu), Reference Center, User Guide. (In WordPerfect 2020, e.g., the topical section is on pages 161-228.) • WordPerfect's Help ► Help Topics (menu): - When the Help window appears click the Search tab, then type "merge" in the "search for" field; then click the List Topics button. - In the list that appears you can specify a topic by clicking on it to select it. - For example: Select "Reference: The Merge Toolbar..."; then click the Display button; then (e.g.) scroll down to "Prompt for user input and message display". • Need to create mailing labels? See Doug Loudenback's Using WordPerfect's Merge To Create Mailing Labels From Quattro Pro. A 4-step PDF tutorial (7 pages) with lots of screen shots. The method is described for Quattro Pro, but it can also be used with Microsoft Excel or a WordPerfect table as the data source. And depending on the merge form file, you can merge the data to postcards, invoices, letters, etc. - not just address labels. • Mail Merge Expert (WordPerfect X7 and later). From the Corel Upgrade Matrix (a PDF on the Corel site):
"The Mail Merge Expert [on the
Tools menu, on the standard <WordPerfect Menu>] is designed to
simplify merging addresses
with letters, labels and envelopes. It guides you step-by-step through
a merge, from choosing the data source that contains the recipients’
information (DAT file) and the form document that has the consistent
content (FRM file) to outputting the merge. You can use a variety of
webmail address books that are in the CSV format in a merge, but you
must first convert them to a DAT file." [Tip:
You can convert any .CSV formatted file (e.g., exported from some email
programs) to a .DAT file with the WordPerfect X7+ shipping macro CSVtoMerge,wcm.]
For more on the Mail Merge Expert see the WordPerfect User Guide (in WordPerfect click on Help ► Reference Center).
• In WordPerfect the source of data for the merge is called (generically) a "merge data file." There are two broad types: a data text file and a data table file [for more see WordPerfect's Help ► Help Topics ► Index (tab): "merge data, creating" [and also "merge data, editing"]. Specifically, the source of the data can be -
◦ a WordPerfect merge data file (see examples in the sections below),
◦ a spreadsheet file (as described in Doug's article above), ◦ a WordPerfect table (i.e., a document containing a table with the source data), ◦ the WordPerfect address book, ◦ your own keyboard input, ◦ a database file from another application, ◦ an ODBC data source, ◦ an ASCII Delimited Text file, ◦ a file in another word processor format. Hence,
you can use any of these types of merge data files as the data source instead
of a spreadsheet.
[Related tip: When formatting "sub" documents that are to be merged or inserted in their entirety into the main document (a.k.a., the merge form), see Gordon McComb's post on WordPerfect Universe here. (A portion of that post is in Footnote 4.)]
Tip: You can, of course, merge data into things other than mailing labels — a common task using a merge. But note that each mailing label on a sheet of labels is considered a "logical page" as described in the left sidebar on this page, so you might want to review Doug's article (see above) when setting up the merge form for mailing labels. • To fill in a form document with a "keyboard merge" see here. • To merge certain data records into (rather than from) a WordPerfect table, whereupon each chosen data record becomes a row in the table, see your WordPerfect's Help (F1). (For example, in WordPerfect X6, search the Index for "merges," then "table creation". Other WordPerfect versions should be similar.) See the method below (or Footnote 3) for the step-by-step procedure to set up the merge-into-table.
Also see below for methods to number the table rows during a merge. • To convert an entire data file into a WordPerfect table (which can make the information more easily accessible for various uses or for tasks such as sorting) see the section "Converting merge data files..." below. • Various aspects of a merge can be automated with embedded macro commands. (See next item. Also see the Macros & Merges Forum on WordPerfect Universe.) • Merge programming commands: See your WordPerfect's Help (F1) and search the index under "merge," "merging," "merge codes," "merge programming commands," etc. Usually there are examples given of the various commands. • ◄- See left column for more tips and techniques. [Page Top]
■ Merging to subdivided pages If you want to merge data to a form that is printed on a subdivided page — e.g., a page that is divided in half (or some other fractional amount), to create two (or more) forms per sheet — then you can try one of these methods. There are at least three ways to do this. ■ Method A Insert the merge command, PageOff, at the very top of the form document to eliminate the hard page code [HPg] between copies of the form file in the merged document. Put your merge codes on the form and merge the data. If your form has several pages and contains hard page breaks, you may need to use PageOn. See WordPerfect's Help (F1) and search for "merge commands." If this doesn't work, try this method: ■ Method B Use the Label definition, Avery 6876, at the top of the form. This creates a physical page divided in half horizontally, producing two sections that are in horizontal format. Of course, you can use ordinary paper instead of label stock when you merge to the form, then shear the paper into sections. Put your merge codes on the form and merge the data. [Note that the sheared sections will be slightly asymmetrical, so you may need to adjust the spacing between labels by editing the label definition. Or, simply use Method C below and create a custom definition from scratch, which is quite easy to do.] Or try this: ■ Method C Create a custom two-column (or two-row) label definition. Then WordPerfect will see the second half of the physical sheet as just another type of label, similar to a sheet of address labels. Example using letter-size pages in landscape orientation, with two forms per sheet. [Page Top]
■ Sorting and/or converting existing address labels If you have an existing document formatted as address labels, i.e., where each part of the address for each label is on a separate line, something like this - John Smith[HRt] 123 Main St.[HRt] Anytown, OR 99999[HPg] - then you can • sort them (e.g., by surnames or by ZIP codes); or
• convert them to a WordPerfect table (which can be sorted and/or used in a merge);or
• convert them to a merge data file.See the following sections for various methods you can use. ■ Method A. Sort address labels by last name (surname) You can use this method suggested by Seth Katz at WPuniverse. It sorts existing labels directly, based on surname, using the Paragraph sort option of the Sort feature. NoteProcedure Always make a
backup of your file first.
[1] Be
sure that all labels are separated by at least two hard returns ([HRt][HRt]) or
they end with a hard page break ([HPg]). [Hard page breaks can be
entered with <Ctrl+Enter>.] Two hard returns or a page
break define a "paragraph" for the sort tool.
[2] Click on Tools, Sort, New. In the "Sort Description" field, enter a name (e.g., "Sort labels by surname"). [3] Click the Sort by Paragraph radio button. [4] Under "Keys (sorting rules)," "Key 1," enter "-1" (without quotes) in the Word field. If you also want to sort duplicate surnames alphabetically by the person's given name, add another key (Key 2) with a "1" (without quotes) in the Line, Field, and Word fields. [5] [Optional:] You may want to use the Options button to allow undoing the sort. [6] Click OK, then Sort. [Note that
the sort will be performed on all labels no matter which label your
cursor is in.]
[Page Top]
■ Method B. Sort address labels by ZIP code This is similar to the procedure above. However, it sorts on the last "word" of the third line of each paragraph — the ZIP code. If your labels do not all have the ZIP code on the third line, the results will be less than optimal. (If the ZIP code is on another line in all labels you can adjust for this below.) Procedure Always make a backup of your file first. [1] First, be
sure that all labels contain at least two hard returns ([HRt]) or
they end with a hard page break ([HPg]). [Hard page breaks can be
entered with <Ctrl+Enter>.] Two hard returns or a page
break define a "paragraph" for the sort tool.
[2] Then click on Tools, Sort, New. In the "Sort Description" field, enter a name (e.g., "Sort labels by ZIP code"). [3] Click the Sort by Paragraph radio button. [4] Under "Keys (sorting rules)," "Key 1," enter "3" (without quotes) in the Line field and "-1" (without quotes) in the Word field. Notes
¤ If the ZIP code is not on line #3 of each label (e.g., it is on Line #4) then enter the correct line number for the current Key (i.e., use "4" in the Line field). ¤ ZIP codes with more than 5 numbers are usually separated by hyphens (e.g., 99020-0451). For this sort to work properly, all hyphens must have been entered with the hyphen key, which produces a hyphen code ([-Hyphen]) in Reveal Codes. [Not all ZIP codes must have hyphens, however. For example, the sort will work with 5-digit ZIPs mixed in with 9-digit ZIPs.] If
the some or all hyphens in the ZIP codes are hyphen characters
(-), then before you can sort the labels you will need to convert all
of these "hard hyphens" to regular hyphen codes
with Find and Replace, as follows:
Go to the top of your label document and click Edit, Find and Replace. Press press Ctrl+hyphen in the Find field, and press hyphen in the Replace field; then use Find Next to locate each one individually and Replace it if it is inside a ZIP code. [Ctrl+hyphen
produces a hard hyphen; also, it can be produced in other programs or
converted from a regular hyphen by WordPerfect during certain paste
operations. For more on the various types of hyphens in WordPerfect,
see here.]
[5] You may want to use the Options button to allow undoing the sort. [6] Click OK, then Sort. [Page Top]
■ Method C. Convert (extract) existing address labels to a table If for some reason the above sorting methods do not work, or if you want to convert existing address labels to a table — perhaps to use them in a merge (see Laura Acklen's tutorial for an example of a table used in a merge) — or to export the data in .CSV (Comma Separated Values) format, here's a way to do it. The 7-step procedure below is a bit more involved than a simple label sort but it may be worth the effort if you have dozens or even hundreds of existing labels in a label document. As with many other unfamiliar things, the procedure is faster to carry out than to explain. Note that this is a one-time procedure for the current label document. On the other hand, if you don't need to convert your address label data to a table (you can always do it later) but you still want to extract and merge the data using WordPerfect — and you are familiar with the merge data file (.DAT) format — see the next section. The procedure there is a bit faster to perform, too. Important notes ¤ The
step-by-step procedure below converts each line
of text
in a label into a separate table cell (a data field) in the same table row. Each row (a data record) of the table
then
will contain the contents of one label. The data in
each table cell in a row can then be used in a merge — such as to Avery labels or envelopes.
[See the basic merge information section above for general help on setting up merges.] ¤ To use a table as a source of data for a merge, the first row of the table (optionally) contains the field names you will create. [See the example data table in Laura Acklen's tutorial.] For example, if the first address label in your existing label document looks like this (e.g., 3 lines of text) -
- then the first and second data table rows might look like this:
¤ Alternative to separating each line of a label into individual table cells: See Footnote 1 for a macro that will copy each entire label as a block of text into a separate table cell. This might be useful (for example) in exporting the table to Microsoft Word where it can be used to print on blank label sheets. Procedure Step 1. You will first need to convert your label document to a document where - • each complete label (called a "logical page" as described in the sidebar here) is
converted from several separate lines (i.e.,
name, address, etc.) into
a single line of text, and where -
• each of the original lines is now separated by a tab code ([Tab]) rather than a hard return ([HRt]), and where - • hard page breaks ([HPg]) are removed (replaced by HRt codes). For example, a label like this (as viewed in Reveal Codes) - John
Smith[HRt]
123 Main St.[HRt] Anytown, OR 99999[HPg] - would be converted to this - John
Smith[Tab]123 Main St.[Tab]Anytown, OR
99999[HRt]
All the content of your labels will then be strung together is such a way that they can be immediately converted to a single table by WordPerfect. However, if the labels in the original address file, as viewed in WordPerfect with Reveal Codes open, does not fit the general format of text and codes shown in the above multi-line example (the actual number of lines isn't typically important, it's the format codes that matter), the procedure below might not work. Also note that some labels might have used line break [Ln Brk] codes instead of hard return [HRt] codes. You should replace line breaks with hard returns (you can use Find and Replace to do it) BEFORE following the next steps. Step 1a. Prepare the document. • Back up the address label document. • Open Reveal Codes to help you see what is happening with various format codes. • In Step 1b and Step 1c below, remove certain format codes from the address label document so as to provide a clean conversion to a table. Step 1b. Remove any existing Tab Set codes. [A highly recommended option for most users.] First remove any [Tab Set] codes by using Find and Replace, replacing them with <Nothing>. This will convert any existing right tabs, decimal tabs, etc., to (default) left tabs before replacing all left tabs in the next step. Here's how: • Go to the very top of your document and place the insertion cursor before (to the left of) all other codes. • From the main WordPerfect menu, click on Edit, Find and Replace. • On the dialog that opens,, click on Match, then on Codes. • Choose the Tab Set code from the Codes dialog that appears, and Insert it. [Note: For some codes you have to scroll down quite a bit to find the exact code you need.] • Click Close on the Codes dialog to return to the Find and Replace dialog. [You can also just use Insert & Close instead of separately pressing Insert and Close.] • The "Replace with" field in Find and Replace should be blank (empty) or just contain the default entry of "<Nothing>". If it contains anything else, delete the entry. Then click Replace All. If no Tab Set codes are found you will see a message to that effect. Step 1c. Remove any existing Left Tab codes - temporarily or permanently. Search for [Left Tab] codes: • Go to the very top of your document before all codes and open Find and Replace (if it's not already open). • Click on Match, then on Codes. Choose the Left Tab code from the Codes dialog, and Insert it. [Important: This code differs from similar left tab codes (such as ...Left Tab), and it is quite far down in the list. See the image below for some adjacent codes to help you locate it.] • Click Close on the Codes dialog to return to the Find and Replace dialog. [You can also just use Insert & Close instead of separately pressing Insert and Close.] • The "Replace with" field in Find and Replace should be blank (empty) or just contain the default entry of "<Nothing>". If it contains anything else, delete the entry. Replace with characters or a symbol: [If you haven't already done so, please read the information ("Why remove them temporarily?") above before using the next replace-the-code step. You might want to simply remove all existing [Left Tab] codes rather than temporarily hide them with a "nonsense" character string or symbol as the next step does.] • In the "Replace with" field: Enter a character string or symbol (use Ctrl+W to enter a symbol) that is not likely to be found in your labels document. (Here, some characters from the keyboard were used.) Then click Replace All. Any [Left Tab] codes in your labels should be replaced with these temporary characters or symbol. If no tab codes are found you will see a message to that effect. Step 2. Delete the [Labels Form] code from the top of the document. • Just
drag the [Labels Form] code out of the Reveal Codes window, or use the
Delete or Backspace key to remove it. [You can also delete the [Paper
Sz/Type] and other top-of-the document codes if you
wish.]
This will remove the label format (page layout) and return your document to a standard size. Each label should now be on one or more separate full-size pages. Step 3. Replace all hard return [HRt] codes with [Left Tab] codes: [Note that some labels might have used line break [Ln Brk] codes instead of hard return [HRt] codes. You should replace line breaks with hard returns (you can use Find and Replace to do it) before following the next steps.]Step 4. Replace all [HPg] codes with [HRt] codes. • Go to the top of the document. Use Find and Replace in the same way as in Step 3 to change hard page breaks ([HPg]) to hard returns ([HRt]):Step 5. Convert the tab-separated lines of text to a table. Here's how (from WP9 Help):Step 6. If you started this process by replacing left tabs with temporary characters or symbols (Step 1c), you can replace or remove these temporary items now. • Use Find and Replace
and replace them with Left Tabs to return your label text to its
original state -or- replace them with single spaces or with
<Nothing> if you no longer need these tabs.
• Remember you can use Edit, Undo if you don't like the effect of replacing or removing them. Step 7. Finally, trim the table of any excess spaces, rows, or columns, and join cells if required, add needed columns, etc. • You can then sort the table (Tools, Sort) or use it in a merge, etc.
If the table is used in a marge
you might want to insert a single "field name" row at the top of the
table. It will contain your names for the fields (cells) that contain
data to merge into various locations in the merge form. (See the brief
example at the top of this section.)
Just right-click in the first address row and then choose Insert,
Rows, (1), Before, OK. Then type the desired field names in that row that will
correspond to the fields on your merge form. This can help identify the
cells in the table.
Tips [Page Top]
■ Method D. Convert (extract) existing address labels to a merge data file (.DAT) This method uses WordPerfect's Find and Replace feature to change an existing file of address labels to a merge data file by adding certain merge codes to the file and reformatting the file to remove hard page codes between records. [Further: The data file can be instantly converted to a WordPerfect table (rows=records, columns=fields), if desired. The table can then also be used as a data file. See here.] As with many other unfamiliar things, the procedure is faster to carry out than to explain. Note that this is a one-time procedure for the current label document. Step 1. • Always make a
backup of your label file first.
• In the labels document, open the Reveal Codes window and delete the [Labels Form] code at the top of the document. This changes the document to one where each label is on its own, separate (standard full-size) page. Step 2. • Position the
cursor at the very top of the document. Click on Edit, Find and
Replace. With the cursor in the "Find:" field of the Find and Replace
dialog, click Match, Codes.
• In the small Codes dialog that pops up, scroll down and select HRt, and then click Insert to insert one [HRt] code in the "Find:" field. Step 3. You now need to insert two codes in Find and Replace's "Replace with:" field.
• Position the cursor in the "Replace with:" field and insert a HRt code there. Notes
¤ If the Codes button is still on screen, just click Insert. If it's not on screen you can just select the [HRt] code in the "Find:" field (see Step 2), then copy it to the clipboard and then paste it into the "Replace with:" field. ¤ The "Find:" field is now renamed by the program to "Replace". • Important: Position the cursor in front (i.e., to the left side) of that [HRt] code. • Check (tick) the box "Display merge codes only" at the top of the Codes dialog (see image in Step 2). This will change the "Find codes" window to show merge codes. • Scroll down and select ENDFIELD, then click Insert, then Close (or just Insert & Close). The "Replace" and "Replace with:" fields should now look like this: Step 4. • Click
Replace All in the Find and Replace dialog.
• When all replacements are made, click OK to dismiss the confirmation message (you can leave the other dialogs onscreen if they are still open). • Click in the document and position the cursor at the very top of the document so that you can begin the next Find and Replace. Step 5.
In this step, you need to change the item that Find and Replace will seek.
• Position the cursor in the "Replace" field of the Find and Replace dialog. • Delete the [HRt] code (e.g., with Backspace) you just used, then insert a [HPg] code in its place. [If the Codes dialog is not onscreen, click Match, Codes..., HPg, Insert on the Find and Replace dialog. The image in Step 2 above shows the HPg code located a few choices above the HRt code in the Codes dialog.] See next image's "Replace" field for the result. Step 6. • Position the
cursor in the "Replace with:" field, and use the Replace, Codes dialog to insert another [HRt] code at the
end
of the codes already there. [Alternatively, you could simply select the
existing [HRt] code, copy it with Ctrl+C, then paste the copy with
Ctrl+V.]
The Find and Replace fields should now look like this: Step 7. You now need to separate all records with a [MRG:ENDRECORD] code.
• Position the cursor between the two [HRt] codes in the "Replace with:" field. [If the Codes dialog is not open, click on Replace, Codes (and tick the box, "Display merge codes only" in the Codes dialog).] • Scroll down and select ENDRECORD in the Codes dialog, then click Insert, then Close. [You can also just use Insert & Close instead of separately pressing Insert and Close.] The Find and Replace fields should now look like this: [Expanded for clarity:] [MRG:ENDFIELD][HRt][MRG:ENDRECORD][HRt]
Step 8. Click
Replace All in the Find and Replace dialog.
• When all replacements are made, click OK to dismiss the message, and Close the Find and Replace dialog. • Your document should now contain merge data records that look something like this: Jane DoeENDFIELD
12 Ash StreetENDFIELD Anytown, OR 99999ENDFIELD ENDRECORD John DoeENDFIELD 34 Oak StreetENDFIELD Anytown, OR 99999ENDFIELD ENDRECORD ...etc. In this example each record has 3 fields to merge into 3 corresponding fields on a merge form. Tips: Step 9. Save this data
file with a .DAT filename extension (e.g., MyLabels.dat).
The merge data file can now be - • associated with a merge form and be used to merge letters, envelopes, labels, etc. [See WordPerfect's Help (F1) for more information on merging, as well as the tutorials above];
or
• converted to a WordPerfect table using the method below for easier maintenance (sorting, etc.) and merging; or
• converted to a .CSV file (using the method below) for exporting to other programs that can use that format. [Page Top]
■ Converting tables to merge data files (.DAT) or plain text To convert a table to a merge data file (.DAT) or ordinary text: Procedure Always make a backup of your file first. Step 1. Prepare the table. For modern versions of WordPerfect:
• With the cursor
placed anywhere inside the table, use the WordPerfect main menu and choose Edit, Select, Select Table;
• Press the Delete key (-or- use the Table Property Bar and click the Table drop button, then click the Delete... choice); • The Delete Table dialog appears; go to Step 2. For some early versions of WordPerfect: • With the cursor
placed anywhere inside the table, click Select Table on the Table
Property Bar and select all cells; then click the Table button on the
Property Bar, then click Delete (this brings up the Delete Table dialog); then
• Select Table on the Table Property Bar and select all cells; then click the Table button on the Property Bar, then click Delete; then • The Delete Table dialog appears; go to Step 2. Tip related to any WordPerfect version:
A shortcut alternative for Step 1 is to use Reveal Codes and delete just the [Tbl Def] code, which will bring
up the Delete Table dialog. (In this case the table is not shown as selected.)
Step 2. Convert the table. For modern versions of WordPerfect:
• To convert the table to a
merge data file
- On the Delete Table dialog choose the "Convert table contents... radio button, then click OK. This brings up another dialog entitled Convert: Table to Text.
- Choose "Convert text to merge data file (.dat)" (if desired, click the box "Use text in first row as field names"). - Click OK. This converts the table to a document where each row (i.e., record) is a page ending with ENDRECORD and each column (i.e, field) ends with ENDFIELD — i.e., a data file. You can then use the document (saved with a .DAT extension) to merge into a form (.FRM) document — including (e.g.) address label sheets with a label form set up with merge commands (e.g., see Doug Loudenback's tutorial here about merging from a QuattroPro spreadsheet to mailing labels — which is similar to using a WordPerfect table as the data source). • To convert the table to ordinary text - On the Delete Table dialog choose the "Convert table contents... radio button, then click OK. - Choose "Convert tables to text," and then choose one of the related 4 options (e.g., to convert each table cell line to ordinary text ending with a hard return, choose "Separate text with paragraphs (hard returns)"). - Click OK. For some early versions of WordPerfect: • To convert the table to a
merge data file
On the Delete Table dialog choose one of the "Convert contents to merge data file" options. This converts the table to a file where each row (i.e., record) is a page ending with ENDRECORD and each column (i.e, field) ends with ENDFIELD — i.e., a data file. You can then use the data file (saved with a .DAT extension) to merge into a form (.FRM) document — including (e.g.) address label sheets set up with merge commands. • To convert the table to ordinary text On the Delete Table dialog choose "Table structure" from the Delete Table dialog, then OK. This deletes just the table structure, converting the table's contents to ordinary text. Tip related to any WordPerfect version:
You should be able to undo your conversions with Edit, Undo or Ctrl+Z.
[Page Top]
■ Converting merge data files (.DAT) to WordPerfect tables for sorting/merging; merging data files into a table; and converting data files to "comma-separated-values" (.CSV) files Note: Always make a backup of your file first before using any of these procedures. ■ Method A. CONVERT a merge data file (.DAT) to a WordPerfect table in a document. This is easier than Method B — but Method B has various uses in complex documents.
A merge data file is one where each record ends with ENDRECORD and each field in the record ends with ENDFIELD. Step 1. Open the merge data file (.DAT) and select the entire file with Edit, Select, All. (Note: A shortcut like Ctrl+A may not work here, so use the Edit, Select, All method.) Step 2. Click on Table, Create (in WordPerfect 9 and earlier, use Insert, Table). A "convert" dialog pops up, with several choices such as "Tabs" (or "Tabular column"), "Parallel Columns," "Merge Data File," etc. Here, choose "Merge Data File". Step 3. Enable both "Equal Column Widths" and "Merge Data File". Click OK, then save the file. You now should have a WordPerfect table with multiple rows (records) and columns (fields) — which (1) can be sorted and/or (2) be used as the source data for a merge, if desired. (You might want to review the table and edit it for any incorrect data and formatting issues before using it in a merge.) ■ Method B. MERGE a data file (.DAT) into a WordPerfect table in a document. Here's how to merge
a traditional data file (.DAT), where each record ends with ENDRECORD and each field ends with ENDFIELD, into a normal
WordPerfect
table with multiple rows (records) and columns (fields).
[These steps were tested in WordPerfect X7, but should be similar back to at least WPWin6.1.] Step 1. Create a merge form with Tools, Merge. Click the Form Document button and choose Create Form Document. This opens the Associate Form and Data dialog. Choose the "Associate a data file" button, and then choose the data file (.DAT) from the adjacent browse field and click Select. Click OK to close the Associate Form and Data dialog. Click Cancel to close the Merge dialog. The Merge bar (Insert Field..Options) should still be visible above the document's text area. [Tip: If there are lots of fields in a record you may want to set the form document to Landscape (go to the very top and click Format, Page, Page Setup), and also set the page's font size to a very small size before converting the data to a table. (You can always Zoom in to the small text with View, Zoom.)] Step 2. Create a two-row table in the merge form with Table, Create (in WordPerfect 9 and earlier, use Insert, Table). Specify as many columns as there are fields in a record in your data file. Step 3. Type headings into each cell in the first row. These help identify your merged data (see below for an example). Note: The first row is optional but it helps identify the type of data in each column in the merge data file and the merged output. Place the cursor in the first cell of the second row, then click the Insert Field button on the Merge Toolbar (image from WordPerfect X9). Select the field name from the "Insert Field Name or Number" dialog (just click the name), then click Insert. [You can leave this dialog on screen, and move the cursor to the next field name, and repeat the Insert process.] At the end of the last cell in the second row (after all codes), click Insert Merge Code on the Merge Toolbar, and choose "More...". Find REPEATROW in the Codes list and click Insert, then Close. Click Close on the Insert Field Name or Number dialog. You should see something like this (assuming you are using something like the example 3-line address labels in the section above):
Important: Before leaving these table-creation steps (#2 and #3): With the cursor in the table, use Table, Format (or just right-click the table). On the Table tab in the Properties dialog, be sure that "Insert new rows automatically" is enabled. Click OK to close that dialog. Tip: See also the merge commands NEXTRECORD*, PAGEOFF/PAGEON, ONERROR and other merge and/or macro commands that may be revelant. Footnote 2 gives an example of these commands. - - - - - - - - - - * Note that NEXTRECORD
is typically used to search the next record(s) in a data file (.dat) or
when merging into tables (see WordPerfect's Help under "Merge
Commands"). But should it be used at the end of a form file (.frm) to (presumably) make the program merge the next record into that form? Generally, the answer is no. The reason is that the program might then skip every other record when performing the merge into the form!
Noal Mellot (on WordPerfect Universe here) explains: "A merge normally processes each record for (each passage of) the frm-file. When NEXTRECORD is the very last command in the frm-file, the merge encounters it and advances to the next record, but the merge then encounters the end of the frm-file and advances on its own one more record. So the NEXTRECORD command, in that position at the very end of the frm-file, has made the merge skip a record.... By the way, REPEATROW (normally used in a table) contains internally its own NEXTRECORD instruction." Step 4. Merge the file as you would any other form file: Click Merge on the merge bar to open the Merge dialog, output to a New Document, etc. Then click the Merge button at the bottom of the Merge dialog. The new document will have a table where the first row contains the headings and the remaining rows contain the merged data, one record per row. You now should have a WordPerfect table with multiple rows (records) and columns (fields) — which (1) can be sorted and/or (2) be used as the source data for a merge, if desired. (You might want to review the table and edit it for any incorrect data and formatting issues before using it in a merge.) ■ Method C. CONVERT a merge data file (.DAT) to a Comma-Separated-Values (.CSV) file. Here's
how to convert a simple merge data text file (.DAT) to a comma-separated file
(.CSV) [a.k.a. a comma-delimited file], a file where each record is on
its own line and each field in the record is separated by a comma, and
which Microsoft Word (or other program that can read such data)
should recognize.
Note that any address lines in your data file that contain commas will confuse this method, so there should be deleted first. [The U.S. Post Office prefers eliminating commas and periods from mailing addresses, so this should not be a problem.]* Back up the file first. Go to the top of the document and choose Edit, Find and Replace. Step 1. Find all commas (,) and replace with a space character (press Spacebar in the "Replace with" field). Step 2. Find [HPg] codes and replace with a [HRt]. Step 3. Find all [ENDFIELD][HRt] code pairs and replace them with a comma (,). Note that the Codes dialog you used has a small checkbox to "Display merge codes only". Enable that box to search for just merge codes. Step 4. Find all ,[ENDRECORD] pairs (i.e., a comma plus an [ENDRECORD] code) and replace them with <Nothing> to delete them. The file will now be a "comma separated values" file. Be sure to save it with a .CSV filename extension before exporting it.** Update (Apr 2021): As an alternative to Steps 1-4: Two methods: [1] Using any file manager, right-click the .DAT file name, and Open With... QuattroPro. Then Save As (file type) .CSV in QuattroPro. [2] In WordPerfect, save the file as ASCII (DOS) Delimited Text. (Thanks to Roy 'lemoto' Lewis on WordPerfect Universe here for these tips.) ---------- * Generally, if a comma is required in a field it can be added back (in the final .CSV file) in that field if the entire field is enclosed in double quote marks. For example: "San Francisco, CA". Most programs that can use a .CSV file will then see the entire field as a single (literal) string of characters rather than two fields separated by a comma. [Similarly, fields with existing quote marks should be enclosed in double quotes.] For more on .CSV format and its requirements see (e.g.) https://en.wikipedia.org/wiki/Comma-separated_values ** You can do the opposite: To convert data in .CSV (Comma Separate Values) format (e.g., exported from some email programs) to a WordPerfect .DAT file, see the Corel shipping macro, CSVtoMerge,wcm, included in WordPerfect X7 and later versions. ■ Extract table cell data that is not in merge format so it can be used as a merge data file There are many possible table formats, so let's use a relatively simple example. Hopefully, the methods will be useful in your own work. Suppose you have a table with a single column, containing data like this -
etc.
The problem here — insofar as a WordPerfect merge is concerned — is that the table cells contain data that is separated into one-line "fields" with hard returns. That is, each part of each address is on a separate line ending with a [HRt] code. You need fields that end with ENDFIELD merge codes, and where each record ends with an ENDRECORD merge code. Therefore, you have to extract the data from the table and convert it to a merge data file, so that it looks like this: John
SmithENDFIELD
123 Main StreetENDFIELD Portland OR 97229ENDFIELD ENDRECORD Mary JonesENDFIELD 456 South AveENDFIELD Seattle WA 98110ENDFIELD ENDRECORD Bob BlackENDFIELD 678 Western BlvdENDFIELD San Francisco CA 96200ENDFIELD ENDRECORD etc. Here is one way to solve the problem, though it probably will require some editing of the table or data file before you can use it in a merge. Procedure Always make a backup of your file first. [Note: This works in WordPerfect 10 and later versions:] First you need to convert the one-column table (where each cell has a name and address — names, cities, states, etc., separated by spaces — and each line ends in a hard return) into a format that can then be converted into a merge data file. [1] Use Find and
Replace, and Find all [HRt] codes (with F&R's
Match>Codes) in the table and Replace all of them with [Left
Tab] codes (with F&R's Replace>Codes). Each cell in your
table should now have its contents in one continuous line, with each segment
(i.e., field) separated by a left tab. (If any data — such as
City/State/Zip — are separated with spaces, but should be separated by
left tabs into separate fields, use Find and Replace to do the job.)
[2] Insert a new row at the top of the table and use it for Field names, separated by the same number of tabs as you find in a typical data row. (Use Ctrl+Tab to insert left tabs into a table cell.) [3] Delete the table structure (only) by deleting the [Tbl Def] code in Reveal Codes, and when the Delete Table dialog appears choose "Convert Table Contents," then choose "Convert tables to text - Separate text with tabs." The data should now be in ordinary text with each line constituting a data record, and with each record's data fields separated by tabs. [4] To ensure that the data is in the correct columns, select the data and click Table, Create, (choose the number of columns to match the row with the most number of fields; this should be automatically done by WordPerfect), set Table Delimiters to tabs, then click OK. You should now have a table again, with data fields separated into individual columns. (The first row is the fieldname row.) [5] Make any corrections (use cut-and-paste) to your data. [6] Delete the [Tbl Del] code again, click "Convert table contents to" and choose "Convert text to merge data file" and be sure to check the box, "Use text in first row as field names." [7] Click OK. You should now have a standard merge data file. [Tip: A merge data file can be converted to a table for easy maintenance, sorting, merging, etc. See the section here.] ■ How to edit just one field in several records of a merge data file Here are a couple of relatively simple ways to edit several items in just one field of a data file with multiple records, such as just the ZIP code field. (Make a backup of the file first.) ■ Method A [1] If the
data file is not already in table format, convert it to a table
using
the tips above.
[2] Delete all columns except the one you want to process. [3] Process the column — perhaps by using Edit, Find & Replace, or with a macro. [4] Select this edited column and copy it to the clipboard. [5] Open a copy of the original data file with the table in it, and insert a new, empty column adjacent to the old (unedited) one. [6] Paste the edited column into the table. [7] Delete the old column. [8] If desired, convert the data table back to a text data file using the tips above. [Thanks to Karen Fiorello for this tip.] ■ Method B Use a merge to generate a new data file (.dat):
Create a new data file as the merged output of the first data file, using a form file that contains the various FIELD() commands — but with a MRGCMND in the form file. Thanks to Noal Mellott at WordPerfect Universe for this tip, which is demonstrated here. [For more on this or other merge programming commands, See WordPerfect's Help file or the Macros & Merges forum at WordPerfect Universe. ] ■ Workarounds for disappearing bookmarks in merges ☼ Here's a tip from Lorna Cattell in a WordPerfect Universe post ("Workaround for disappearing bookmarks in merges"): "...☼ From Noal Mellott on a WordPerfect Universe thread ("Merge deletes bookmark"): [Note:
Essentially, the method takes your original "merge form" and inserts it
into another merge form file (.FRM) during the merge. This second form
file contains (for example) just the macro commands to process the
bookmarks contained in the first file. Put another way, the second form
file encompasses the first form file during the merge, preventing the
creation of duplicate bookmarks as discussed in the previous tip above. For an example of the method see this post on WordPerfect Universe.]
"The DOCUMENT() command provides a way to retain bookmarks.
This command inserts the file named in its parameter into the merge like an ordinary document. If the file is a form file, it is not processed, and any merge codes it contains will be passed on to the merge output. By the way, DOCUMENT(C:\Documents and Settings\My Documents\test.frm) it is the equivalent of EMBEDMACRO(FileInsert("C:\Documents and Settings\My Documents\test.frm")). Each inserts the designated form file without processing its commands. Notice, however, that the first takes no quote marks! To its advantage, the inserted document brings [retains] its bookmarks, whence a way of having the merge output retain bookmarks. ..." [Note:
The DOCUMENT() command is more often used to assemble various parts of
the merged output document. ("Document assembly") It might be a good
idea to explore using the above method — a form file with just the
commands needed to assemble the document.
From the Help file in WordPerfect X6: "...
Use DOCUMENT to insert the named document into the merged document at the DOCUMENT command. The document is not processed as a merge file, so any merge commands in the inserted document are included in the file but not executed. This command is commonly used for inserting variable paragraphs in contracts and similar documents (often called document assembly) or for building a form or data file. Example In the following example, DOCUMENT inserts the document called oneroom.mrg in the merged document if the variable rooms is equal to 1, or it inserts the document tworooms.mrg if the variable rooms is not equal to 1. CODES( CHAR(rooms;Enter the number of rooms (1 or 2); Number of Rooms) IF(VARIABLE(rooms)=1) DOCUMENT(c:\mrgfiles\oneroom.mrg) ELSE DOCUMENT(c:\mrgfiles\tworooms.mrg) ENDIF ) ..." ■ Automatically number table rows (or items) when you merge into a table You can automatically number table rows (or items in column cells) sequentially when you merge data into a table. There are several ways to do it: with a counter, a formula, or a macro. ■ Method A You can do it by inserting a WordPerfect counter in any cell in the merge form's table that contains the NEXTRECORD() command. (This is the "merge fields row," which is duplicated for each record to be merged from the data file.) This could be used to automatically number the cells in the first column (e.g., "Item #") or any other column (e.g., "Description," etc.) during the merge of data into the table. Basic technique: See Using WordPerfect Counters. Be sure to note the order of insertion of the two components of the counter. For example, suppose you have a merge form that uses a WordPerfect table with various cells and merge fields, something like this (first row is a title row):
Here, the counter codes are shown in blue for illustration only. You will actually see them in Reveal Codes in the table (not in the main document window), once you create the counter as described in Using WordPerfect Counters. Advantages: (1) Counters are easy and simple to set up. Creating and inserting the counter codes takes only a minute or two. See Using WordPerfect Counters. (2) The counter codes can be placed inside any cell in the merge fields row, even if the cell contains merge codes. (In the above example they are placed before the Case field in the first column, followed by a space — but they could be placed before or after any merge field in any cell.) (3) You can add text characters before and/or after the counter (a period, colon, space, brackets, a text label, etc.). (4) The cell can even have its Numeric Format set to Text and it will still increment the counter during the merge. (5) The counter should not interfere with any chained macro you might use (with the CHAINMACRO() command). ■ Method B You can do it using a table formula in any cell in the merge form's table that contains the NEXTRECORD() command. (This is the "merge fields row," which is duplicated for each record to be merged from the data file.) Basic technique: In that cell, right click and set the Numeric Format to General or Integer. Use the main WordPerfect menu and click Table, Formula Toolbar to display the Table Formula property bar (or right-click in that cell and make the same choice). In the toolbar's blank field, type (without quotes) "+ROW()-1" (assuming the first row is a header row and the cursor is in the second row, and want to start with the number "1"; it might help to experiment with the starting number). Click on the blue checkmark button to insert the formula in the cell. The number "1" should appear. Subsequent cells (if any) in that column should be numbered sequentially when the form is merged. Advantages and disadvantages: (1) Note that even though this method is as easy as Method A, it requires the initial ("seed") cell's Numeric Format to be set to General or Integer, and not Text. (2) As with Method A, you can have prefix or suffix characters added to the numbers, but the formula in the initial cell will be a bit more complex than the example given above ("+ROW()-1"). For example, to add the prefix word "Item" plus a space to the numbers (here, you should retain the quote marks around the text characters): +CONCAT("Item ",TEXT(ROW()-1)). (3) This method can also be used with the CHAINMACRO() command). ■ Method C You can do it by using a chained macro with the CHAINMACRO() merge command. Basic technique: See Footnote 2. Advantages and disadvantages: Note that this method (which was posted here before the other methods) is often not as simple and easy to do as other methods, and it does not have the advantages cited for Methods A and B. However, it is included here (in Footnote 2) because chained macros can have other purposes — such as forcing a calculation of the table after data has been merged into it, cleaning up areas of the form, etc. — and which also could be used along with the counter or table formula methods. Tips ☼ You
could use the above table example to create an Invoice.
To do it you can simply add a row below the merge fields row, that should contain a Total cell with a formula (in the Cost column) to sum the cells above it in the column. Typing (without quote marks) "++" as the formula for the Total cell should do the job. You could also use CHAINMACRO() to play a macro to force the recalculation of the table with just these two commands: TableCalculateAll
Return ☼ You can use both Method A and Method B in the same merge form. |
|||||||||||||||||||||||||
Footnote 1 [Continued from above...]
Copying complete address (or other) labels into a table
The procedure above, Convert existing address labels to a table, converts each line of text in a label into a separate table cell. Each row of the table then will contain the contents of one label. The table can then be sorted and/or further processed to create a merge data file. On the other hand, the macro below should create a new document from one composed entirely of WordPerfect labels (i.e., it will have a [Paper Sz/Typ] and [Labels Form] code at the very top) into a new document composed entirely of a normal WordPerfect table. It does this by copying the entire contents of each label into its own separate table cell in a new document. This might be useful in exporting the table to Microsoft Word. (You probably will need to tweak the format of the table's font size, row and column margins, etc., so that it will fit the new label sheet.) [Also, as noted above, you can also sort the table and/or convert the table to a standard WordPerfect merge data file very easily. To convert it: Go to the top of the document, and in the Reveal Codes window, delete the [Tbl Def] code. This will pop up a Delete Table dialog, and you can select "Convert contents to merge data file."] The method below was tested in WPX6 with about 60 normal, unformatted address labels. NOTE: The first command in the macro (vCols:=) should be set to the desired number of columns in the table (corresponding to the number of columns in the paper label stock) — usually, 3 or 4. (It is currently set to 3.) The macro will figure out how many rows are needed. [To copy this macro into your WordPerfect see here.] Instructions
Put the cursor anywhere on the labels and play the macro. The screen will flicker a bit since the macro needs to go back and forth between documents to copy the label text into the table cells. Additional formatting might be needed on the resulting table (font size, column and row margins, etc.). // Macro code begins // // Converts a document made up of WP labels into a WP table. // Additional formatting might be needed on the resulting table // (font size, column and row margins, etc.) // // NOTE: Specify the number of table columns desired: vCols:=3 // If(?NumberOpenDocuments>8) MessageBox(;"Too Many Open Documents (9)"; "At least one available document 'slot' is required."+NToC(0F90Ah)+ "Close one or more open documents and try again.";IconStop!) Quit EndIf If(?DocBlank) MessageBox(;"Current Document is Blank"; "This macro requires text that can be processed.";IconStop!) Quit EndIf // Convert the labels to a WP table: // Store the current document's number: vCurrentDoc:=?DocNumber // Store the number of pages (labels): PosDocBottom vTotalPages:=?Page PosDocVeryTop // Open a new document: FileNew ///CenterPages(Off!) // Store the new document's number: vNewDoc:=?DocNumber // Create the table: vTotalRows:=vTotalPages/vCols // (number of rows needed) vFrac:=FractionalPart(vTotalRows) If(vFrac>0) vTotalRows:=(vTotalRows+1)-vFrac Endif TableCreate(vCols;vTotalRows) ///QuickmarkSet // ("mark" the current cell) PosTableEnd vLastCell:=?Cell PosTableBegin ForNext(vIndex; 1; vTotalPages; 1) // Go back to the original document: SwitchDoc(vCurrentDoc) // Copy the entire label's text: PosPageTop SelectMode(On!) PosPageBottom PosLineVeryEnd If(StrLen(?SelectedText)=0) // (prevents an error) SelectOff Type(" ") // i.e., one space character SelectCharPrevious Endif EditCopy // Copy selection to clipboard SelectOff PosPageNext // Go to the table document: SwitchDoc(vNewDoc) // Paste the label's text into the table cell: EditPasteSimple vCurrentCell:=?Cell PosCellNext EndFor Return // Macro code ends Footnote 2 [Continued from above...] Merging into a table and
automatically numbering the rows
Note: See the
calling section above
about using WordPerfect counters or table formulas. Those methods are
easier and simpler to produce automatic numbering than the technique
below, which was
posted here earlier. However, using a macro can have other purposes,
such as forcing a calculation of the table after data has been merged
into it, creating Bates numbering (see the QwikFill macro code), etc., so it
was decided to retain the following material, which
might be helpful in some other way.
Here is a macro (based on the QwikFill macro) which can automatically add consecutive numbering in the first column of a table in a merge form. For example, suppose you have a merge form that uses a WordPerfect table with various cells and merge fields, something like this (first row is a title row):
In the merge form you can use a macro like the one ("numbering.wcm" — see macro code below) to do the column numbering. You would use the CHAINMACRO() merge command to start the macro at the end of the merge (if the merge terminates normally). It will then add the incrementing numbers in the empty cells in the first column. Notes: 1. In our example
merge form above, the
chained macro is named numbering.wcm
and it is saved in the user's default macro folder (specified in Tools,
Settings, Files, Merge/Macro). It can be any name, as long as it is
the same name as used in the CHAINMACRO() command.
2. See the comments in the macro code below. If you wish to make further modification to the macro's operation you can examine the code in the QwikFill macro for some ideas. 3. If you are merging to a form that has additional material outside the table structure, the cursor would not normally be inside the table when the data is merged. Therefore, you should use the optional command below, PosTableCell("Table A.A1"), to position the cursor inside the table. In our example it's assumed you will be merging to Table A. If it's another table such as Table B, use that table's name instead (i.e., PosTableCell("Table B.A1")). Alternative: You could use some code in the macro to first find a pre-existing bookmark inside the table and position the cursor there (e.g., anywhere in the top row). 4. Numeric format: The blank cells where numbering will be inserted should have their Numeric Format set to General, and not (e.g.) to Text. Otherwise the macro command TableDataFill will not work as expected to fill the column with incrementing numbers. 5. Suffix characters: It seems that the merge function does not like periods (full stops) as a suffix to the numbers. Use a colon or some other character in the vSuffixChar variable below. (This issue does not arise when using the QwikFill macro on a regular table.) Macro code for above example: [To copy this macro into your WordPerfect
see here.]
// Macro code begins // // This macro assumes the first row in the table // is a "title" row of text labels, and the macro // will populate the first column with incrementing // numbers starting in row #2, using the // initial number stored in the vStart variable. // The suffix character(s) — here, a colon, stored // in the vSuffixChar variable — can be changed and // even omitted by setting vInsertSuffix:=0. // // Optional choices - // Turn ON the option to add a suffix to number (1=On, 0=Off): vInsertSuffix:=1 // Store the desired suffix (N.B.: periods/fullstops don't work): vSuffixChar:=":" // // Macro processing begins here - // Get number of table rows whose first cells are to be filled: // First, position the cursor: If it might not be in the table, use // the next command to position it in Table A (assuming it should // be inside Table A and not some other table) by deleting the // preceding slash marks: //PosTableCell("Table A.A1") // (Optional - see Notes above) PosTableBegin // Then, get the total number of rows (minus 1): PosTableColumnBottom vRows:=?Row-1 // Set the starting number value - vStart:=1 // // Begin processing the table column - // First, "seed" the numbering sequence - PosTableBegin // (go to cell A1) PosTableCellDown // (go to row #2) Type(vStart) // (type the first number) If(?Row=vRows+1) // (test if in last row; if so exit macro) PosLineEnd Type(vSuffixChar) Return // (or use Quit) Endif PosTableCellDown Type(vStart+1) // (type the second number) // Go back to first numbered cell - PosTableCellUp // Populate the cells - PosTableCellTop // (i.e., beginning of cell) // Select the rest of the column - SelectOn (CharMode!) RepeatValue (vRows) PosTableCellDown // Fill the column with incrementing numbers - TableDataFill // (same as "QuickFill" command) SelectOff // Optional: Go to table top left cell - PosTableBegin // Optional: Add a suffix to numbers, such as // colons or other punctuation specified above - If(vInsertSuffix=1) PosTableCellDown // (go to row #2) PosLineEnd Type(vSuffixChar) ForNext(i; 1; vRows-1; 1) PosTableCellDown PosLineEnd Type(vSuffixChar) Endfor PosTableBegin // (Optional: Go to table top) Endif Return // (or use Quit) // Macro code ends Footnote 3 [Continued from above...] [See also Footnote 2 above for a way to automatically number the table rows.]
From WPX6/WPX7 Help (F1), "To create a table [from] a merge" (annotated):
1. Click Tools > Merge. 2. In the Merge dialog box, click Form document > Create form document. If there is text in the active document, enable one of the following options in the Data file source dialog box: • Use file in active window — uses the active document
• New document window — creates a new document 3. In the Associate form and data dialog box, enable one of the following options and click OK: • Associate a data file — specifies the path and filename for the associated data file
• Associate an address book — specifies an address book • Associate an ODBC data source — lets you select an ODBC source • No association — does not associate any data file 4. On the WordPerfect menu bar, click Table > Create and in the Create table dialog box, type the specified values in the following boxes: • Columns — number of columns [to contain the data from the data file; see also the Tips below]
• Rows — 2 5. Click Create, and type a heading in each cell of the first row (e.g., First Name, Last Name, Street Address, etc.). 6. Right-click the table, click Format, and on the Table tab, enable the Insert new rows automatically check box, and click OK. 7. Insert fields [i.e., FIELD() merge codes] in the second row of the table, and click Close. 8. Click at the end of the last cell in the second row [i.e., after all codes in that cell], and on the Merge toolbar (image from WordPerfect X9), click "Insert merge code" and choose More. 9. In the Insert merge codes dialog box, choose REPEATROW from the Merge codes list, click Insert, and click Close. - - - Notes - After merging, the table expands one row for each record in the associated data file. - Press Tab to move to the next cell. Tips - See also the merge commands NEXTRECORD, PAGEOFF/PAGEON, ONERROR (and other merge and/or macro commands that may be revelant). - [From a post by Larry Lewis on WordPerfect Universe here:] If you want the table cells in each row to contain individual records rather than individual fields in a single record (i.e., one record per row), place all the FIELD() merge codes for a record in the first cell in the row, then duplicate that cell for the remaining cells in the row (no need for headings in this case).Then add NEXTRECORD at the bottom of each cell in that row except for the last cell, which should contain REPEATROW, something like this (assuming a 4-column table, which should produce a table with 4 records per row):
Footnote 4 [Continued from above...]
From Gordon McComb (here):
"... When preparing [separate] sub documents for merging or inserting, people will often "format" them for better appearance as a stand-alone document. This includes putting a font code, tab set, header or footer, or other formatting at the start of the document body. That code will often be an open (unpaired) code, but that doesn't really matter, as when the document is imported into the output, WPWin will convert most of these to paired code (there are some exceptions, like tab sets, headers and footers, and so on). When this document is subsequently merged in, these codes go with the text. [Italics added.] This is not always (and is often not) desirable. You get font and other formatting changes when you don't want them, headers and footers that "mysteriously" change, and if you need to update the look of the document, you have to go through all the subdocuments as well. It's always better to leave formatting out of the documents if you don't specifically want that formatting to be included in the out[put]. Or, if you must apply formatting to better visualize the document, put the codes in [the initial] DocumentStyles [code], where they will not be inserted during a merge or import. ..." [Ed.: You can just double-click on the Open Style: DocumentStyle code at the top of the document to add formatting there that applies to the entire document. Search the Toolbox site for examples of "hide the code".] Footnote 5 [Continued from above...] WordPerfect's bookmarks
(Tools, Bookmark — or their macro equivalents) can be useful in many
situations, such as finding marked material in a document (even in a
merged document during the merge) so that it can be additionally
processed.
As noted above, however, bookmarks in a merge are removed by default in the merged documents. To compensate for this and be able to use bookmarks in a merge, the merge form document could contain an EMBEDMACRO() command, such as in the following example — which not only uses bookmarks (created during the merge) to apply text attributes, it also processes the merged data inserted from a specific data file field to convert it from a dollar amount to a legal style currency format using an external macro. [The external macro named in the code below is Mike Koenecke's ConvNum.wcm, a free macro that is run during the merge using the MacroFilePlay command. It can covert plain numbers (e.g., 10,000.00) — and also dollars ($), pounds (£), yen (¥), euros (€) — depending on what your computer uses for currency values. See http://www.macros.koenecke.us/ for the download macro file and the included Readme.wpd file.] If you don't want to apply text attributes to the converted data you can use the alternative code at the end of this footnote. But it might help you with other projects to see how paired bookmarks are used to re-select typed data so the selected material can be processed further. Example: Merge currency in numerical data form and convert it into legal style text in the merged documents:
Suppose you have a merge form (*.FRM) with this boilerplate, where the *** indicates a dollar amount to be merged from the data file: "Party 1 shall pay Party 2 the sum of *** as compensation for ...."
Assume the data file (*.DAT) contains multiple records where Field(1) of each record has values like $1,000.00 (etc.). In the merge form (.FRM) you could create a sentence containing merge commands and macro commands like the code below. Notes: • BE SURE to:
[1] use the correct FIELD(nnn) merge command's number (nnn) corresponding to your own data file; and
[2] place the convnum.wcm macro in your default (or supplemental) macro folder as shown in Tools, Settings, Files, Merge/Macro (or else use the full, specific path and macro name in the MacroFilePlay() command in the code below). Then you can use something like the sample merge code below in your merge form. • Variations: Note that for your own purposes you could omit the MacroFilePlay() and If..Endif commands and thus not convert the data. You could also change the Attribute... command(s) to any other text attribute (Bold, Redline, etc.) — see comments ("//") in the code. Of course, it might be simpler to just apply such text attributes directly in the merge form document, but the purpose of this example is to show how to do it at the time the data is merged into the form by using a paired bookmark to locate and re-select the field's merged data as often as needed. If you wish to omit this example's text attributes and just convert the data, see the alternative code below. • To test the merge formatting code without doing a merge: Just copy all commands from SelectWord() to BookmarkDelete() into a temporary macro file. (For help see here.) Then select a currency number in a document such as $12,345.67 and play that temporary macro. It should convert the number into the legal style form: Twelve Thousand Three Hundred Forty-Five and 67/100 Dollars ($12,345.67). Merge document — sample merge form text and merge/macro code: "Party 1 shall pay Party 2 the sum of CODES(
ASSIGN(vAmt; FIELD(1)) // (<— use your own data's Field number) EMBEDMACRO( Type (vAmt) SelectWord // (<— assumes a contiguous character string like $1,000.00) // Create a paired bookmark from the selected data — this allows multiple // operations on merged data by using BookmarkBlock to re-select the item: BookmarkCreate ("Amount") BookmarkBlock ("Amount") // (selects the typed data again) // Play an external macro to convert the data: MacroFilePlay (?PathMacros + "convnum.wcm") If (?LeftChar=" ") DeleteCharPrevious Endif // (remove any trailing space) // Optionally apply italics and underline to the converted data: BookmarkBlock ("Amount") // (select the converted data) AttributeAppearanceOn (Attrib:Italics!) AttributeAppearanceOn (Attrib:Underline!) PosBlockBottom // (move to the end of the selection, and clean up) SelectOff BookmarkDelete ("Amount") )) as compensation for ...." [Note the terminating "))" parenetheses in the last line to balance the merge and macro codes segment.]
Result:
This would result in a merged document containing data (e.g., $1,000.00) that is inserted (typed) as:
"Party 1 shall pay Party 2 the sum of One Thousand and no/100 Dollars ($1,000.00) as compensation for ...." Alternative code to above example: Assume you just want to convert the currency data without adding any text attributes (as in the previous example):
"Party 1 shall pay Party 2 the sum of CODES(
ASSIGN(vAmt; FIELD(1)) // (<— use your own data's Field number) EMBEDMACRO( Type (vAmt) SelectWord // (<— assumes a contiguous character string like $1,000.00) // Play an external macro to convert the data: MacroFilePlay (?PathMacros + "convnum.wcm") If (?LeftChar=" ") DeleteCharPrevious Endif // (remove any trailing space) SelectOff )) as compensation for ...." [Note the terminating "))" parenetheses in the last line to balance the merge and macro codes segment.]
Result:
This would result in a merged document containing data (e.g., $1,000.00) that is inserted (typed) as:
"Party 1 shall pay Party 2 the sum of One Thousand and no/100 Dollars ($1,000.00) as compensation for ...." |
||||||||||||||||||||||||||