DOCX: Field code that evaluates to empty string as field result

208 views Asked by At

I need to insert the field in the word document which ultimately evaluates to empty string.

Some ideas I've;

- Set intersection: both sets have nothing in common and finally field result would lead to empty.
- "".concats(""), leads to ""

Can we insert such kind of field code in office word document?

1

There are 1 answers

2
Dirk Vollmar On BEST ANSWER

If all you want is to insert a field with an empty string as the result you could use a MACROBUTTON field with no caption that points to a non-existing macro:

{ MACROBUTTON NoMacro }

Using the OpenXML SDK, you can create such a button like this:

var paragraph = new Paragraph(
    new Run(new FieldChar { FieldCharType = FieldCharValues.Begin }),
    new Run(new FieldCode { Space = SpaceProcessingModeValues.Preserve, 
                            Text = " Macrobutton NoMacro " }),
    new Run(new FieldChar() { FieldCharType = FieldCharValues.End }));