Search code examples
c#ms-wordopenxmldocx-mailmerge

C# OpenXML Mail Merge mergeformat


I am using OpenXML to handle a mailmerge. I am feeding in data from a json file to merge with my document.

I have this working great, but then I need to take in the formatting that is described in the MERGEFORMAT, as it doesn't look like OpenXML is handling this for me.

I have coded for the CAPS, FirstCap, Upper and Lower. Also coded (not tested yet) for the date and time formatting (starts with \@ ) and also managed \f and \b. (Not sure what to do about \m or \v.

I am now looking at doing the numbers, but while I see a number starts with #, I am not really sure how to apply the number options in code.

Firstly, am I going about this correctly (applying all this in code) or is there something I am missing that I can use in the SDK?

Secondly, how do I work with the numbers?

Thirdly, are there any merge options that I am missing?

Thanks.


Solution

  • After my comment... I did wonder if the string.ToString() was overloaded, so did further looking.

    While a string.ToString() doesn't have the overload, the double does... so, convert the numeric string to a double, then .ToString that with the number format required.

    https://learn.microsoft.com/en-us/dotnet/standard/base-types/custom-numeric-format-strings

    Thanks for looking.