com.aspose.words

Interface IFieldResultFormatter

  • public interface IFieldResultFormatter 

Implement this interface if you want to control how the field result is formatted.

Example:

Shows how to control how the field result is formatted.
public void insertCustomFormattingField() throws Exception
{
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);

    Field field = builder.insertField("=-1234567.89 \\# \"### ### ###.000\"", null);
    doc.getFieldOptions().setResultFormatter(new FieldResultFormatter("[{0}]", null));

    field.update();

}

private class FieldResultFormatter implements IFieldResultFormatter
{
    FieldResultFormatter(String numberFormat, String dateFormat)
    {
        mNumberFormat = numberFormat;
        mDateFormat = dateFormat;
    }

    public String formatNumeric(double value, String format)
    {
        mNumberFormatInvocations.add(new Object[]{value, format});

        return (mNumberFormat == null || "".equals(mNumberFormat)) ? null : MessageFormat.format(mNumberFormat, value);
    }

    public String formatDateTime(Date value, String format, /*CalendarType*/int calendarType)
    {
        mDateFormatInvocations.add(new Object[]{value, format, calendarType});

        return (mDateFormat == null || "".equals(mDateFormat)) ? null : MessageFormat.format(mDateFormat, value);
    }

    public String format(String value, /*GeneralFormat*/int format)
    {
        throw new UnsupportedOperationException();
    }

    public String format(double value, /*GeneralFormat*/int format)
    {
        throw new UnsupportedOperationException();
    }

    private /*final*/ String mNumberFormat;
    private /*final*/ String mDateFormat;

    private /*final*/ ArrayList mNumberFormatInvocations = new ArrayList();
    private /*final*/ ArrayList mDateFormatInvocations = new ArrayList();
    private IFieldResultFormatter fieldResultFormatterImplementation;
}

Method Summary
abstract java.lang.Stringformat(double value, int format)
Called when Aspose.Words applies a number format switch, i.e. \* Ordinal.
abstract java.lang.Stringformat(java.lang.String value, int format)
Called when Aspose.Words applies a capitalization format switch, i.e. \* Upper.
abstract java.lang.StringformatDateTime(java.util.Date value, java.lang.String format, int calendarType)
Called when Aspose.Words applies a date/time format switch, i.e. \@ "dd.MM.yyyy".
abstract java.lang.StringformatNumeric(double value, java.lang.String format)
Called when Aspose.Words applies a numeric format switch, i.e. \# "#.##".
 

    • Method Detail

      • format

        public abstract java.lang.String format(double value, int format)
        Called when Aspose.Words applies a number format switch, i.e. \* Ordinal. The implementation should return null to indicate that the default formatting should be applied.
        Parameters:
        format - A GeneralFormat value.
      • format

        public abstract java.lang.String format(java.lang.String value, int format)
        Called when Aspose.Words applies a capitalization format switch, i.e. \* Upper. The implementation should return null to indicate that the default formatting should be applied.
        Parameters:
        format - A GeneralFormat value.
      • formatDateTime

        public abstract java.lang.String formatDateTime(java.util.Date value, java.lang.String format, int calendarType)
        Called when Aspose.Words applies a date/time format switch, i.e. \@ "dd.MM.yyyy". The implementation should return null to indicate that the default formatting should be applied.
        Parameters:
        calendarType - A CalendarType value.
      • formatNumeric

        public abstract java.lang.String formatNumeric(double value, java.lang.String format)
        Called when Aspose.Words applies a numeric format switch, i.e. \# "#.##". The implementation should return null to indicate that the default formatting should be applied.