chrisfcarroll / MailMerge

Merge component for OfficeOpenXml .docx (i.e. Microsoft Word) documents
GNU General Public License v3.0
19 stars 7 forks source link

Code vs. documentation #10

Closed AllTaken closed 3 years ago

AllTaken commented 3 years ago

The documentation states the following regarding "complex" fields:

For a complex field implementation, a set of runs shall be used with each run containing, in sequence, the following elements:

  • fldChar with attribute fldCharType value begin,
  • One or more instrText elements, which, collectively, contain a complete field,
  • Optionally,
    • fldChar with attribute fldCharType value separate, which separates the field from its field result,
    • Any number of runs and paragraphs that contains the most recently updated field result, and
  • fldChar with attribute fldCharType value end.

But the code has the following (in KnownWordProcessingMLTransforms.cs):

else if (separatorRun != null /*17.16.18 only replace after a separator; no separator=no replace*/

Which seems to enforce the opposite? Is this simply a limitation of the library?

chrisfcarroll commented 3 years ago

The code (and that comment) represents my understanding of 17.16.18 pages 1267-1268:

As well, because a complex field can specify both its field codes and its current result within the document, these two items are separated by the optional separator character, which defines the end of the field codes and the beginning of the field contents. The omission of this character shall be used to specify that the contents of the field are entirely field codes (i.e. the field has no result).

I take “the field has no result” to mean that we should do nothing. But if you have an example Docx where Word does do something when there is no separator … ?

AllTaken commented 3 years ago

No. I was just confused by the apparent enforcement of the "opposite" of the docs. I don't think I can get word to actually make a run without a separator. Thanks for the explanation!

chrisfcarroll commented 3 years ago

👍