How do I delete a section out of a paragraph via mailmerge

  • I have used a lot of mailmerge fields to insert data into a template however want to add the ability to delete the entire section between two merge fields eg:
    .... some information <<IFPositive>>display positive info<<ELSE>>display negative information<<ENDIF>>
    How do I do this?

    • Offizieller Beitrag

    Hi,

    Inside the mail merge event this is not possibily. I am thinking of adding such a feature to WPTools 6, though.

    The merge procedure will overread and use the text beween the fields, so fields are not a useful method to do it.

    If you place you code itself into a field or use <<else>> as a texobject, than you can develop code to handle this case.

    <<posititve[ELSE]negative>>

    A simpler approach would be

    <<IFPOSITIVE positve>><<IFNEGATIVE negative>>

    here you have to simple fields and no ELSE.

    Julian

  • 1. If you added this feature to version 6 I would gladly upgrade
    2. As an alternative I have tried to delete the entire paragraph in the MailMerge procedure

    Code
    Contents.MergePar.DeleteParagraph;


    however this causes an Access Violation
    3.What is the best way of programatically searching for unique text in a paragraph and then programatically either delete the text or delete the entire paragraph

  • I have developer (organically) a syntax for choices, I am sure it is not the best way, but I am a WPTools novice and don't get much time on the tool.

    We have letters with the following embedded into them
    <selection:name>
    <choice:name1>
    </choice:name1>
    <choice:name2>
    </choice:name2>
    </selection:name>

    Currently the system searches for these first, i.e.
    <selection:*> then it looks for the closing </selection:whateverwasinthetop>
    It then selects this lot and puts it into another wpRTF and works on that.
    We then spit the result back into the main wprtf

    So we don't use the mergFields part for this at all. Once we have all the choices out of the way, we mailmerge as before.

    Sorry if this is a bit garbled, came across it as I am wrestling with my own if then else type dilemma.

    • Offizieller Beitrag

    Hi,

    this sounds a bit problematic. Esspecially the selection part is not too reliably.

    You can work on the paragraphs itself very powerful, the TParagraph interface has methods to insert and delete characters. This avoids all problems which come from loading and saving text.

    WPTools 6 bundle can work with such templates
    https://www.wpcubed.com/manuals/textdy…_conversion.htm

    Might this be an idea?

    Regards,
    Julian

  • This is one possible approach, although it may be the long way around the block...

    In effect you take the contents of the first TWPRichText component and do a "pre-scan" reading the document paragraph by paragraph into a second "destination" editor.

    Starting at the top of the "source" editor copy the non-conditional paragraphs from the source editor into the "destination" editor. So far, straightforward.

    Okay, you've now come upon a "conditional" field indicator. If it's true, copy the paragraph(s) until you come to the false field indicator. Set a flag in your code that tells you as you continue reading paragraphs from the source document until you come to the end of the false section. Reset that internal flag, and resume the paragraph copying.

    Conversely, if that initial conditional field check isn't true, then set the internal flag to skip all the paragraphs in the "If true" section, read through until you come to the false section, then start the copying over. Come to the end of the false section? Reset the internal flag.

    You've now pre-processed the whole document, run the mailmerge on that destination document.

    Hopefully my description of the process as I see it makes sense AND applies to your situation and needs.

    Regards,
    richard diamond