public class FieldFormat
Example:
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Use a document builder to insert field with no format
Field field = builder.insertField("= 2 + 3");
// We can format our field here instead of in the field code
FieldFormat format = field.getFormat();
format.setNumericFormat("$###.00");
field.update();
// Apply a date/time format
field = builder.insertField("DATE");
format = field.getFormat();
format.setDateTimeFormat("dddd, MMMM dd, yyyy");
field.update();
// Apply 2 general formats at the same time
field = builder.insertField("= 25 + 33");
format = field.getFormat();
format.getGeneralFormats().add(GeneralFormat.LOWERCASE_ROMAN);
format.getGeneralFormats().add(GeneralFormat.UPPER);
field.update();
int index = 0;
Iterator<Integer> generalFormatEnumerator = format.getGeneralFormats().iterator();
while (generalFormatEnumerator.hasNext()) {
System.out.println(MessageFormat.format("General format index {0}: {1}", index++, generalFormatEnumerator.toString()));
}
Assert.assertEquals("LVIII", field.getResult());
Assert.assertEquals(2, format.getGeneralFormats().getCount());
Assert.assertEquals(format.getGeneralFormats().get(0), GeneralFormat.LOWERCASE_ROMAN);
// Removing field formats
format.getGeneralFormats().remove(GeneralFormat.LOWERCASE_ROMAN);
format.getGeneralFormats().removeAt(0);
Assert.assertEquals(format.getGeneralFormats().getCount(), 0);
field.update();
// Our field has no general formats left and is back to default form
Assert.assertEquals(field.getResult(), "58");
Property Getters/Setters Summary | ||
---|---|---|
java.lang.String | getDateTimeFormat() | |
void | setDateTimeFormat(java.lang.Stringvalue) | |
Gets or sets a formatting that is applied to a date and time field result. Corresponds to the \@ switch. | ||
GeneralFormatCollection | getGeneralFormats() | |
Gets a collection of general formats that are applied to a numeric, text or any field result.
Corresponds to the \* switches.
|
||
java.lang.String | getNumericFormat() | |
void | setNumericFormat(java.lang.Stringvalue) | |
Gets or sets a formatting that is applied to a numeric field result. Corresponds to the \# switch. |
public java.lang.String getDateTimeFormat() / public void setDateTimeFormat(java.lang.String value)
Example:
Shows how to formatting fieldsDocument doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Use a document builder to insert field with no format Field field = builder.insertField("= 2 + 3"); // We can format our field here instead of in the field code FieldFormat format = field.getFormat(); format.setNumericFormat("$###.00"); field.update(); // Apply a date/time format field = builder.insertField("DATE"); format = field.getFormat(); format.setDateTimeFormat("dddd, MMMM dd, yyyy"); field.update(); // Apply 2 general formats at the same time field = builder.insertField("= 25 + 33"); format = field.getFormat(); format.getGeneralFormats().add(GeneralFormat.LOWERCASE_ROMAN); format.getGeneralFormats().add(GeneralFormat.UPPER); field.update(); int index = 0; Iterator<Integer> generalFormatEnumerator = format.getGeneralFormats().iterator(); while (generalFormatEnumerator.hasNext()) { System.out.println(MessageFormat.format("General format index {0}: {1}", index++, generalFormatEnumerator.toString())); } Assert.assertEquals("LVIII", field.getResult()); Assert.assertEquals(2, format.getGeneralFormats().getCount()); Assert.assertEquals(format.getGeneralFormats().get(0), GeneralFormat.LOWERCASE_ROMAN); // Removing field formats format.getGeneralFormats().remove(GeneralFormat.LOWERCASE_ROMAN); format.getGeneralFormats().removeAt(0); Assert.assertEquals(format.getGeneralFormats().getCount(), 0); field.update(); // Our field has no general formats left and is back to default form Assert.assertEquals(field.getResult(), "58");
public GeneralFormatCollection getGeneralFormats()
Example:
Shows how to formatting fieldsDocument doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Use a document builder to insert field with no format Field field = builder.insertField("= 2 + 3"); // We can format our field here instead of in the field code FieldFormat format = field.getFormat(); format.setNumericFormat("$###.00"); field.update(); // Apply a date/time format field = builder.insertField("DATE"); format = field.getFormat(); format.setDateTimeFormat("dddd, MMMM dd, yyyy"); field.update(); // Apply 2 general formats at the same time field = builder.insertField("= 25 + 33"); format = field.getFormat(); format.getGeneralFormats().add(GeneralFormat.LOWERCASE_ROMAN); format.getGeneralFormats().add(GeneralFormat.UPPER); field.update(); int index = 0; Iterator<Integer> generalFormatEnumerator = format.getGeneralFormats().iterator(); while (generalFormatEnumerator.hasNext()) { System.out.println(MessageFormat.format("General format index {0}: {1}", index++, generalFormatEnumerator.toString())); } Assert.assertEquals("LVIII", field.getResult()); Assert.assertEquals(2, format.getGeneralFormats().getCount()); Assert.assertEquals(format.getGeneralFormats().get(0), GeneralFormat.LOWERCASE_ROMAN); // Removing field formats format.getGeneralFormats().remove(GeneralFormat.LOWERCASE_ROMAN); format.getGeneralFormats().removeAt(0); Assert.assertEquals(format.getGeneralFormats().getCount(), 0); field.update(); // Our field has no general formats left and is back to default form Assert.assertEquals(field.getResult(), "58");
public java.lang.String getNumericFormat() / public void setNumericFormat(java.lang.String value)
Example:
Shows how to formatting fieldsDocument doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Use a document builder to insert field with no format Field field = builder.insertField("= 2 + 3"); // We can format our field here instead of in the field code FieldFormat format = field.getFormat(); format.setNumericFormat("$###.00"); field.update(); // Apply a date/time format field = builder.insertField("DATE"); format = field.getFormat(); format.setDateTimeFormat("dddd, MMMM dd, yyyy"); field.update(); // Apply 2 general formats at the same time field = builder.insertField("= 25 + 33"); format = field.getFormat(); format.getGeneralFormats().add(GeneralFormat.LOWERCASE_ROMAN); format.getGeneralFormats().add(GeneralFormat.UPPER); field.update(); int index = 0; Iterator<Integer> generalFormatEnumerator = format.getGeneralFormats().iterator(); while (generalFormatEnumerator.hasNext()) { System.out.println(MessageFormat.format("General format index {0}: {1}", index++, generalFormatEnumerator.toString())); } Assert.assertEquals("LVIII", field.getResult()); Assert.assertEquals(2, format.getGeneralFormats().getCount()); Assert.assertEquals(format.getGeneralFormats().get(0), GeneralFormat.LOWERCASE_ROMAN); // Removing field formats format.getGeneralFormats().remove(GeneralFormat.LOWERCASE_ROMAN); format.getGeneralFormats().removeAt(0); Assert.assertEquals(format.getGeneralFormats().getCount(), 0); field.update(); // Our field has no general formats left and is back to default form Assert.assertEquals(field.getResult(), "58");