MailMerge icon indicating copy to clipboard operation
MailMerge copied to clipboard

Feature: Listing all merge fields

Open apumex opened this issue 5 years ago • 1 comments

It would be great if we have an api to list all the merge fields.

apumex avatar Aug 02 '20 04:08 apumex

I'm unlikely to work on this near-term, but I think the choices are:

  1. Refactor the methods for SimpleMergeFields() and ComplexMergeFields() from https://github.com/chrisfcarroll/MailMerge/blob/master/MailMerge/KnownWordProcessingMLTransforms.cs so as to turn each method into two steps, the first of which would be 'list all the mergefields'

  2. Be able to write an XPath query to replace the loop in ComplexMergeFields() with a single query. Then the XPath extension method at https://github.com/chrisfcarroll/MailMerge#extension-methods--helpers would make it a one liner. e.g. for simple merge fields the one liner starts with the XPath query:

var simpleFieldNames=stream
    .AsXPathDocOfWordprocessingMainDocument(isEditable)
    .SelectNodes("//w:fldSimple[contains(@w:instr,'MERGEFIELD ')]"
    , OoXmlNamespace.Manager);

And then AllMergeFields is the union of the SimpleMergeFields and the ComplexMergeFields

chrisfcarroll avatar Aug 04 '20 17:08 chrisfcarroll