Headers/Footers and WPSuperMerge (WPREPORTER)

  • Hi,

    I am using the WPSuperMerge component to create merged letters.

    The problem is that WPSuperMerge ignores normal headers and footers in the template document. I know that the correct way of doing this is to create a Header Band in the template, but I have hidden the band functionality from my users in order to make it as simple as possible for them.

    When the merge button is clicked, my code does this :-

    [1] backup their template letter (to a memstream)
    [2] creates a group band around their letter
    [3] inserts a page break at the end of the group
    [4] opens a new document and calls WPSuperMerge.Execute
    [5] restores their original letter

    This all works perfectly apart from the headers/footers.

    A possible work around would be for me to create a header band and a footer band in code, and then copy the template's header / footer into the correct bands, but I can't work out how to do this!

    Please help!

    Thanks,

    Hedley

    PS : Hope you had a good holiday, but I'm glad you're back!

  • In the sample code I copied, it has

    Code
    wpResult.Header := wpLayout.Header; // Assign page properties


    at the start, which copied the template header properties to the result. Don't know if that will help you, but it's worth mentioning.

    Matthew

  • Hi Julian,

    Thanks for your help so far on this. I am now using this code :-

    Code
    DestWPRichText1.Clear();
        DestWPRichText1.Header.Assign(WPRichText1.Header);
        DestWPRichText1.AsString := WPRichText1.AsString;
        DestWPRichText1.ClearBody();
        WPSuperMerge1.SetSourceDest(SrcRichText1.Memo.RTFData, DestWPRichText1.Memo.RTFData);
        WPSuperMerge1.Execute();

    This now correctly copies over the headers/footers to the destination document, but the SuperMerge component doesn't process merge fields in the header/footer - is it possible to fix this?

    Thanks.

    • Offizieller Beitrag

    Hi,

    Q: ... SuperMerge component doesn't process merge fields in the header/footer - is it possible to fix this?

    A: SuperMerge cannot process the fields but the destination WPRichText can. SImply assign an event handler to DestText.OnMailMergeGetText (this can be the same as used for TWPSuperMerge!) and call
    DestText.MergeText(true) before you do the SuperMerge.Execute.


    Julian

  • Hi Julian - thanks for your quick reply (as always).

    I have tried your suggestion, but the problem now is that the WPRichText.MergeText only merges the current dataset record rather than iterating through the records like supermerge does.

    I'm trying to offer my users a letter mail merge facility. They create a template letter and then select a list of contacts to send the letter.

    They need to be able to create 'normal' looking letter with 'normal' headers/footers and then merge the letter. Trying to get them to use the header/data/footer report bands will be too confusing for them (they're not very it literate!!).

    Is it possible to get WPRichText.MergeText to scroll through the dataset in sync with the SuperMerge?

    Alternatively, is it possible to manipulate their template document at runtime BEFORE the merge? e.g. [1] backup their template [2] create a header band and a footer band [3] copy text from their headers/footers into the appropriate band [4] perform the supermerge [5] restore their document?

    Which of the above is easier? Thanks.

    Thanks Julian

    • Offizieller Beitrag
    Zitat

    Is it possible to get WPRichText.MergeText to scroll through the dataset in sync with the SuperMerge?

    This is not possible since a header/footer text can only be used for one record. You will need to create new sections to have different header/footer in one document.

    I create a procedure which create a template from the header/footer text bands which are currently used. A similar procedure will be in next release of WPSuperMerge for easier use.

    From release 5.17.3 the procedure SuperMerge.ConvertLetterIntoTemplate can be used to do the conversion outlines above.

    Julian