ms-wordmailmergewordperfectdocx-mailmerge

Converting WordPerfect files with mail-merge logic to .docx


I am working with a large number of .frm and .wpd WordPerfect files and I am trying to convert them to .docx while retaining all of the mail-merge logic.

Saving the files as .docx within WordPerfect X6 or opening the .frm/.wpd files from within Word 2016 both result in a complete loss of the mail-merge codes.

Is there any way to convert the WordPerfect files so that they retain similar merge functionality in the .docx format?


Solution

  • Here is a somewhat crazy approach:

    Use WP_Reader to parse the document.

    Collect all the pertinent merge functions (there are a bunch of merge commands, and you will have to figure out which ones you need to translate into Word merge fields).

    Make a dictionary that translates each needed merge function into its WP string "code" (for searching purposes).

    Write a simple WordPerfect macro that uses a passed-in variable to search and replace each merge "code" with a unique text marker.

    Open the document using the WordPerfect.PerfectScript interface.

    Use the PerfectFit.PerfectScript interface to call the WP macro and pass in each merge function you want replaced with its unique marker. You can't make a .NET call to a WordPerfect document to search for anything that is not ASCII text, so you are forced to use a macro and PerfectFit to do this (thanks, Corel!).

    Save the wpd document as a Word document (or probably safer, use Office Interop to do this).

    Use the Office Interop commands to find each unique marker and replace it with a new merge field (I'm a little fuzzy about how this part works).

    This approach comes with a few caveats:

    WP_Reader in its current form does not model any merge functions. This will take a bit of coding, but the approach is pretty straightforward. I'm the only person working on this project, and have not yet had a need for these functions. All of the merge functions either have no parameters or 1 or more strings. These functions should be easy to model, and I can help you get started.

    .frm and .dat files are really WordPerfect files that are set up as merge documents and data sources for merge documents (maybe they are used for other purposes, too). You can use WP_Reader to model those files the same as .wpd files.

    This approach will only work if you have extremely simple merge documents. The WordPerfect merge arena includes its own language, separate from the WP command set. There are If statements, For loops, etc, that would not translate into anything useful in a Word document.

    Before you try this time-consuming project, see if LibreOffice converts wpd files with merge codes directly into the .odt format. The lib-wpd project, which is a built-in program in LibreOffice, has been running since 2003 or so, and they might have already incorporated this functionality. Converting from .odt to .docx should be easy to do.