MailMerge
MailMerge copied to clipboard
Feature: Listing all merge fields
It would be great if we have an api to list all the merge fields.
I'm unlikely to work on this near-term, but I think the choices are:
-
Refactor the methods for
SimpleMergeFields()andComplexMergeFields()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' -
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