public class FieldAutoNum extends Field
To learn more, visit the Working with Fields documentation article.
Remarks:
Inserts an automatic number.
Examples:
Shows how to number paragraphs using autonum fields.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Each AUTONUM field displays the current value of a running count of AUTONUM fields,
// allowing us to automatically number items like a numbered list.
// This field will display a number "1.".
FieldAutoNum field = (FieldAutoNum) builder.insertField(FieldType.FIELD_AUTO_NUM, true);
builder.writeln("\tParagraph 1.");
Assert.assertEquals(" AUTONUM ", field.getFieldCode());
field = (FieldAutoNum) builder.insertField(FieldType.FIELD_AUTO_NUM, true);
builder.writeln("\tParagraph 2.");
// The separator character, which appears in the field result immediately after the number,is a full stop by default.
// If we leave this property null, our second AUTONUM field will display "2." in the document.
Assert.assertNull(field.getSeparatorCharacter());
// We can set this property to apply the first character of its string as the new separator character.
// In this case, our AUTONUM field will now display "2:".
field.setSeparatorCharacter(":");
Assert.assertEquals(" AUTONUM \\s :", field.getFieldCode());
doc.save(getArtifactsDir() + "Field.AUTONUM.docx");
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
getSeparatorCharacter()
Gets the separator character to be used.
|
int |
getSwitchType(java.lang.String switchName) |
void |
setSeparatorCharacter(java.lang.String value)
Sets the separator character to be used.
|
getDisplayResult, getEnd, getFieldCode, getFieldCode, getFormat, getLocaleId, getResult, getSeparator, getStart, getType, isDirty, isDirty, isLocked, isLocked, needStoreOldResultNodes, remove, setLocaleId, setResult, unlink, update, updatepublic java.lang.String getSeparatorCharacter()
Examples:
Shows how to number paragraphs using autonum fields.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Each AUTONUM field displays the current value of a running count of AUTONUM fields,
// allowing us to automatically number items like a numbered list.
// This field will display a number "1.".
FieldAutoNum field = (FieldAutoNum) builder.insertField(FieldType.FIELD_AUTO_NUM, true);
builder.writeln("\tParagraph 1.");
Assert.assertEquals(" AUTONUM ", field.getFieldCode());
field = (FieldAutoNum) builder.insertField(FieldType.FIELD_AUTO_NUM, true);
builder.writeln("\tParagraph 2.");
// The separator character, which appears in the field result immediately after the number,is a full stop by default.
// If we leave this property null, our second AUTONUM field will display "2." in the document.
Assert.assertNull(field.getSeparatorCharacter());
// We can set this property to apply the first character of its string as the new separator character.
// In this case, our AUTONUM field will now display "2:".
field.setSeparatorCharacter(":");
Assert.assertEquals(" AUTONUM \\s :", field.getFieldCode());
doc.save(getArtifactsDir() + "Field.AUTONUM.docx");
public void setSeparatorCharacter(java.lang.String value)
throws java.lang.Exception
Examples:
Shows how to number paragraphs using autonum fields.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Each AUTONUM field displays the current value of a running count of AUTONUM fields,
// allowing us to automatically number items like a numbered list.
// This field will display a number "1.".
FieldAutoNum field = (FieldAutoNum) builder.insertField(FieldType.FIELD_AUTO_NUM, true);
builder.writeln("\tParagraph 1.");
Assert.assertEquals(" AUTONUM ", field.getFieldCode());
field = (FieldAutoNum) builder.insertField(FieldType.FIELD_AUTO_NUM, true);
builder.writeln("\tParagraph 2.");
// The separator character, which appears in the field result immediately after the number,is a full stop by default.
// If we leave this property null, our second AUTONUM field will display "2." in the document.
Assert.assertNull(field.getSeparatorCharacter());
// We can set this property to apply the first character of its string as the new separator character.
// In this case, our AUTONUM field will now display "2:".
field.setSeparatorCharacter(":");
Assert.assertEquals(" AUTONUM \\s :", field.getFieldCode());
doc.save(getArtifactsDir() + "Field.AUTONUM.docx");
value - The separator character to be used.java.lang.Exceptionpublic int getSwitchType(java.lang.String switchName)