com.aspose.words

Class FieldUpdateCultureSource

  • java.lang.Object
    • com.aspose.words.FieldUpdateCultureSource
public class FieldUpdateCultureSource 
extends java.lang.Object

Utility class containing constants. Indicates what culture to use during field update.

Example:

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.getFont().setLocaleId(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
Locale currentLocale = Locale.getDefault();
Locale.setDefault(new Locale("en", "US"));

// Execute a mail merge for the first MERGEFIELD using the current culture (US English) for date formatting
doc.getMailMerge().execute(new String[]{"Date1"}, new Object[]{new SimpleDateFormat("yyyy/MM/DD").parse("2011/01/01")});

// Execute a mail merge for the second MERGEFIELD using the field's culture (German) for date formatting
doc.getFieldOptions().setFieldUpdateCultureSource(FieldUpdateCultureSource.FIELD_CODE);
doc.getMailMerge().execute(new String[]{"Date2"}, new Object[]{new SimpleDateFormat("yyyy/MM/DD").parse("2011/01/01")});

// The first MERGEFIELD has received a date formatted in English, while the second one is in German
Assert.assertEquals(doc.getRange().getText().trim(), "Saturday, 1 January 2011 - Samstag, 1 Januar 2011");

// Restore the original culture
Locale.setDefault(currentLocale);

Field Summary
static final intCURRENT_THREAD = 0
The culture of the current execution thread is used to update fields.
static final intFIELD_CODE = 1
The culture specified in the field formatting properties via language setting is used.
 

    • Field Detail

      • CURRENT_THREAD = 0

        public static final int CURRENT_THREAD
        The culture of the current execution thread is used to update fields.
      • FIELD_CODE = 1

        public static final int FIELD_CODE
        The culture specified in the field formatting properties via language setting is used. To be exact, Aspose.Words mimics MS Word by using the language set for the first character of the field code.
        See Also:
        Field.LocaleId