DocumentFieldOptions Property

Gets a FieldOptions object that represents options to control field handling in the document.

Namespace:  Aspose.Words
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.8.0


public FieldOptions FieldOptions { get; }

Property Value

Type: FieldOptions


Shows how to specify where the culture used for date formatting during field update and mail merge is chosen from.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Insert two merge fields with German locale
builder.Font.LocaleId = 1031;
builder.InsertField("MERGEFIELD Date1 \\@ \"dddd, d MMMM yyyy\"");
builder.Write(" - ");
builder.InsertField("MERGEFIELD Date2 \\@ \"dddd, d MMMM yyyy\"");

// Store the current culture in a variable and explicitly set it to US English
CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");

// Execute a mail merge for the first MERGEFIELD using the current culture (US English) for date formatting
doc.MailMerge.Execute(new[] { "Date1" }, new object[] { new DateTime(2020, 1, 01) });

// Execute a mail merge for the second MERGEFIELD using the field's culture (German) for date formatting
doc.FieldOptions.FieldUpdateCultureSource = FieldUpdateCultureSource.FieldCode;
doc.MailMerge.Execute(new[] { "Date2" }, new object[] { new DateTime(2020, 1, 01) });

// The first MERGEFIELD has received a date formatted in English, while the second one is in German
Assert.AreEqual("Wednesday, 1 January 2020 - Mittwoch, 1 Januar 2020", doc.Range.Text.Trim());

// Restore the original culture
Thread.CurrentThread.CurrentCulture = currentCulture;

See Also