Click or drag to resize
CalendarType Enumeration
Specifies the type of a calendar.

Namespace: Aspose.Words
Assembly: Aspose.Words (in Aspose.Words.dll) Version: 19.11
Syntax
public enum CalendarType
Members
  Member nameValueDescription
Gregorian0 The Gregorian calendar.
Hijri1 The Hijri Lunar calendar.
Hebrew2 The Hebrew Lunar calendar.
SakaEra3 The Saka Era calendar.
UmAlQura4 The Um-al-Qura calendar.
Examples
Shows how to control how the field result is formatted.
public void FieldResultFormatting()
{
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);

    doc.FieldOptions.ResultFormatter = 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.FieldOptions.ResultFormatter).PrintInvocations();

    // Our formatter has also overridden the formats that were originally applied in the fields
    Assert.AreEqual("$5", doc.Range.Fields[0].Result);
    Assert.IsTrue(doc.Range.Fields[1].Result.StartsWith("Date: "));
    Assert.AreEqual("Item # 2:", doc.Range.Fields[2].Result);
}

/// <summary>
/// Custom IFieldResult implementation that applies formats and tracks format invocations
/// </summary>
private class FieldResultFormatter : IFieldResultFormatter
{
    public FieldResultFormatter(string numberFormat, string dateFormat, string generalFormat)
    {
        mNumberFormat = numberFormat;
        mDateFormat = dateFormat;
        mGeneralFormat = generalFormat;
    }

    public string FormatNumeric(double value, string format)
    {
        mNumberFormatInvocations.Add(new object[] { value, format });

        return string.IsNullOrEmpty(mNumberFormat) ? null : string.Format(mNumberFormat, value);
    }

    public string FormatDateTime(DateTime value, string format, CalendarType calendarType)
    {
        mDateFormatInvocations.Add(new object[] { value, format, calendarType });

        return string.IsNullOrEmpty(mDateFormat) ? null : string.Format(mDateFormat, value);
    }

    public string Format(string value, GeneralFormat format)
    {
        return Format((object)value, format);
    }

    public string Format(double value, GeneralFormat format)
    {
        return Format((object)value, format);
    }

    private string Format(object value, GeneralFormat format)
    {
        mGeneralFormatInvocations.Add(new object[] { value, format });

        return string.IsNullOrEmpty(mGeneralFormat) ? null : string.Format(mGeneralFormat, value);
    }

    public void PrintInvocations()
    {
        Console.WriteLine("Number format invocations ({0}):", mNumberFormatInvocations.Count);
        foreach (object[] s in mNumberFormatInvocations)
        {
            Console.WriteLine("\tValue: " + s[0] + ", original format: " + s[1]);
        }

        Console.WriteLine("Date format invocations ({0}):", mDateFormatInvocations.Count);
        foreach (object[] s in mDateFormatInvocations)
        {
            Console.WriteLine("\tValue: " + s[0] + ", original format: " + s[1] + ", calendar type: " + s[2]);
        }

        Console.WriteLine("General format invocations ({0}):", mGeneralFormatInvocations.Count);
        foreach (object[] s in mGeneralFormatInvocations)
        {
            Console.WriteLine("\tValue: " + s[0] + ", original format: " + s[1]);
        }
    }

    private readonly string mNumberFormat;
    private readonly string mDateFormat;
    private readonly string mGeneralFormat;

    private readonly ArrayList mNumberFormatInvocations = new ArrayList();
    private readonly ArrayList mDateFormatInvocations = new ArrayList();
    private readonly ArrayList mGeneralFormatInvocations = new ArrayList();

}
See Also