java.lang.Object
com.aspose.words.CalendarType
public class CalendarType
- extends java.lang.Object
Utility class containing constants.
Specifies the type of a calendar.
Example:
Shows how to control how the field result is formatted.
public void fieldResultFormatting() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
doc.getFieldOptions().setResultFormatter(new FieldResultFormatter("${0}", "Date: {0}", "Item # {0}:"));
// Insert a field with a numeric format
builder.insertField(" = 2 + 3 \\# $###", null);
// Insert a field with a date/time format
builder.insertField("DATE \\@ \"d MMMM yyyy\"", null);
// Insert a field with a general format
builder.insertField("QUOTE \"2\" \\* Ordinal", null);
// Formats will be applied and recorded by the formatter during the field update
doc.updateFields();
((FieldResultFormatter) doc.getFieldOptions().getResultFormatter()).printInvocations();
// Our formatter has also overridden the formats that were originally applied in the fields
Assert.assertEquals(doc.getRange().getFields().get(0).getResult(), "$5");
Assert.assertTrue(doc.getRange().getFields().get(1).getResult().startsWith("Date: "));
Assert.assertEquals(doc.getRange().getFields().get(2).getResult(), "Item # 2:");
}
/// <summary>
/// Custom IFieldResult implementation that applies formats and tracks format invocations
/// </summary>
private static class FieldResultFormatter implements IFieldResultFormatter {
public FieldResultFormatter(final String numberFormat, final String dateFormat, final String generalFormat) {
mNumberFormat = numberFormat;
mDateFormat = dateFormat;
mGeneralFormat = generalFormat;
}
public String formatNumeric(final double value, final String format) {
mNumberFormatInvocations.add(new Object[]{value, format});
return (mNumberFormat == null || "".equals(mNumberFormat)) ? null : MessageFormat.format(mNumberFormat, value);
}
public String formatDateTime(final Date value, final String format, final int calendarType) {
mDateFormatInvocations.add(new Object[]{value, format, calendarType});
return (mDateFormat == null || "".equals(mDateFormat)) ? null : MessageFormat.format(mDateFormat, value);
}
public String format(final String value, final int format) {
return format((Object) value, format);
}
public String format(final double value, final int format) {
return format((Object) value, format);
}
private String format(final Object value, final int format) {
mGeneralFormatInvocations.add(new Object[]{value, format});
return (mGeneralFormat == null || "".equals(mGeneralFormat)) ? null : MessageFormat.format(mGeneralFormat, value);
}
public void printInvocations() {
System.out.println(MessageFormat.format("Number format invocations ({0}):", mNumberFormatInvocations.size()));
for (Object[] s : (Iterable<Object[]>) mNumberFormatInvocations) {
System.out.println("\tValue: " + s[0] + ", original format: " + s[1]);
}
System.out.println(MessageFormat.format("Date format invocations ({0}):", mDateFormatInvocations.size()));
for (Object[] s : (Iterable<Object[]>) mDateFormatInvocations) {
System.out.println("\tValue: " + s[0] + ", original format: " + s[1] + ", calendar type: " + s[2]);
}
System.out.println(MessageFormat.format("General format invocations ({0}):", mGeneralFormatInvocations.size()));
for (Object[] s : (Iterable<Object[]>) mGeneralFormatInvocations) {
System.out.println("\tValue: " + s[0] + ", original format: " + s[1]);
}
}
private String mNumberFormat;
private String mDateFormat;
private String mGeneralFormat;
private ArrayList mNumberFormatInvocations = new ArrayList();
private ArrayList mDateFormatInvocations = new ArrayList();
private ArrayList mGeneralFormatInvocations = new ArrayList();
}
Field Summary |
static final int | GREGORIAN = 0 | |
The Gregorian calendar.
|
static final int | HIJRI = 1 | |
The Hijri Lunar calendar.
|
static final int | HEBREW = 2 | |
The Hebrew Lunar calendar.
|
static final int | SAKA_ERA = 3 | |
The Saka Era calendar.
|
static final int | UM_AL_QURA = 4 | |
The Um-al-Qura calendar.
|
GREGORIAN = 0 | |
public static final int GREGORIAN |
-
The Gregorian calendar.
HIJRI = 1 | |
public static final int HIJRI |
-
The Hijri Lunar calendar.
HEBREW = 2 | |
public static final int HEBREW |
-
The Hebrew Lunar calendar.
SAKA_ERA = 3 | |
public static final int SAKA_ERA |
-
The Saka Era calendar.
UM_AL_QURA = 4 | |
public static final int UM_AL_QURA |
-
The Um-al-Qura calendar.
See Also:
Aspose.Words Documentation - the home page for the Aspose.Words Product Documentation.
Aspose.Words Support Forum - our preferred method of support.