public class FieldListNum extends Field
To learn more, visit the Working with Fields documentation article.
Examples:
Shows how to number paragraphs with LISTNUM fields.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// LISTNUM fields display a number that increments at each LISTNUM field.
// These fields also have a variety of options that allow us to use them to emulate numbered lists.
FieldListNum field = (FieldListNum) builder.insertField(FieldType.FIELD_LIST_NUM, true);
// Lists start counting at 1 by default, but we can set this number to a different value, such as 0.
// This field will display "0)".
field.setStartingNumber("0");
builder.writeln("Paragraph 1");
Assert.assertEquals(" LISTNUM \\s 0", field.getFieldCode());
// LISTNUM fields maintain separate counts for each list level.
// Inserting a LISTNUM field in the same paragraph as another LISTNUM field
// increases the list level instead of the count.
// The next field will continue the count we started above and display a value of "1" at list level 1.
builder.insertField(FieldType.FIELD_LIST_NUM, true);
// This field will start a count at list level 2. It will display a value of "1".
builder.insertField(FieldType.FIELD_LIST_NUM, true);
// This field will start a count at list level 3. It will display a value of "1".
// Different list levels have different formatting,
// so these fields combined will display a value of "1)a)i)".
builder.insertField(FieldType.FIELD_LIST_NUM, true);
builder.writeln("Paragraph 2");
// The next LISTNUM field that we insert will continue the count at the list level
// that the previous LISTNUM field was on.
// We can use the "ListLevel" property to jump to a different list level.
// If this LISTNUM field stayed on list level 3, it would display "ii)",
// but, since we have moved it to list level 2, it carries on the count at that level and displays "b)".
field = (FieldListNum) builder.insertField(FieldType.FIELD_LIST_NUM, true);
field.setListLevel("2");
builder.writeln("Paragraph 3");
Assert.assertEquals(" LISTNUM \\l 2", field.getFieldCode());
// We can set the ListName property to get the field to emulate a different AUTONUM field type.
// "NumberDefault" emulates AUTONUM, "OutlineDefault" emulates AUTONUMOUT,
// and "LegalDefault" emulates AUTONUMLGL fields.
// The "OutlineDefault" list name with 1 as the starting number will result in displaying "I.".
field = (FieldListNum) builder.insertField(FieldType.FIELD_LIST_NUM, true);
field.setStartingNumber("1");
field.setListName("OutlineDefault");
builder.writeln("Paragraph 4");
Assert.assertTrue(field.hasListName());
Assert.assertEquals(" LISTNUM OutlineDefault \\s 1", field.getFieldCode());
// The ListName does not carry over from the previous field, so we will need to set it for each new field.
// This field continues the count with the different list name, and displays "II.".
field = (FieldListNum) builder.insertField(FieldType.FIELD_LIST_NUM, true);
field.setListName("OutlineDefault");
builder.writeln("Paragraph 5");
doc.updateFields();
doc.save(getArtifactsDir() + "Field.LISTNUM.docx");
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
getListLevel()
Gets the level in the list, overriding the default behavior of the field.
|
java.lang.String |
getListName()
Gets the name of the abstract numbering definition used for the numbering.
|
java.lang.String |
getStartingNumber()
Gets the starting value for this field.
|
int |
getSwitchType(java.lang.String switchName) |
boolean |
hasListName()
Returns a value indicating whether the name of an abstract numbering definition is provided by the field's code.
|
Node |
remove()
Removes the field from the document.
|
void |
setListLevel(java.lang.String value)
Sets the level in the list, overriding the default behavior of the field.
|
void |
setListName(java.lang.String value)
Sets the name of the abstract numbering definition used for the numbering.
|
void |
setStartingNumber(java.lang.String value)
Sets the starting value for this field.
|
getDisplayResult, getEnd, getFieldCode, getFieldCode, getFormat, getLocaleId, getResult, getSeparator, getStart, getType, isDirty, isDirty, isLocked, isLocked, needStoreOldResultNodes, setLocaleId, setResult, unlink, update, updatepublic Node remove() throws java.lang.Exception
Fieldnull.
Examples:
Shows how to remove fields from a field collection.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.insertField(" DATE \\@ \"dddd, d MMMM yyyy\" ");
builder.insertField(" TIME ");
builder.insertField(" REVNUM ");
builder.insertField(" AUTHOR \"John Doe\" ");
builder.insertField(" SUBJECT \"My Subject\" ");
builder.insertField(" QUOTE \"Hello world!\" ");
doc.updateFields();
FieldCollection fields = doc.getRange().getFields();
Assert.assertEquals(6, fields.getCount());
// Below are four ways of removing fields from a field collection.
// 1 - Get a field to remove itself:
fields.get(0).remove();
Assert.assertEquals(5, fields.getCount());
// 2 - Get the collection to remove a field that we pass to its removal method:
Field lastField = fields.get(3);
fields.remove(lastField);
Assert.assertEquals(4, fields.getCount());
// 3 - Remove a field from a collection at an index:
fields.removeAt(2);
Assert.assertEquals(3, fields.getCount());
// 4 - Remove all the fields from the collection at once:
fields.clear();
Assert.assertEquals(0, fields.getCount());
Shows how to process PRIVATE fields.
public void fieldPrivate() throws Exception {
// Open a Corel WordPerfect document which we have converted to .docx format.
Document doc = new Document(getMyDir() + "Field sample - PRIVATE.docx");
// WordPerfect 5.x/6.x documents like the one we have loaded may contain PRIVATE fields.
// Microsoft Word preserves PRIVATE fields during load/save operations,
// but provides no functionality for them.
FieldPrivate field = (FieldPrivate) doc.getRange().getFields().get(0);
Assert.assertEquals(" PRIVATE \"My value\" ", field.getFieldCode());
Assert.assertEquals(FieldType.FIELD_PRIVATE, field.getType());
// We can also insert PRIVATE fields using a document builder.
DocumentBuilder builder = new DocumentBuilder(doc);
builder.insertField(FieldType.FIELD_PRIVATE, true);
// These fields are not a viable way of protecting sensitive information.
// Unless backward compatibility with older versions of WordPerfect is essential,
// we can safely remove these fields. We can do this using a DocumentVisiitor implementation.
Assert.assertEquals(2, doc.getRange().getFields().getCount());
FieldPrivateRemover remover = new FieldPrivateRemover();
doc.accept(remover);
Assert.assertEquals(remover.getFieldsRemovedCount(), 2);
Assert.assertEquals(doc.getRange().getFields().getCount(), 0);
}
/// <summary>
/// Removes all encountered PRIVATE fields.
/// </summary>
public static class FieldPrivateRemover extends DocumentVisitor {
public FieldPrivateRemover() {
mFieldsRemovedCount = 0;
}
public int getFieldsRemovedCount() {
return mFieldsRemovedCount;
}
/// <summary>
/// Called when a FieldEnd node is encountered in the document.
/// If the node belongs to a PRIVATE field, the entire field is removed.
/// </summary>
public int visitFieldEnd(final FieldEnd fieldEnd) throws Exception {
if (fieldEnd.getFieldType() == FieldType.FIELD_PRIVATE) {
fieldEnd.getField().remove();
mFieldsRemovedCount++;
}
return VisitorAction.CONTINUE;
}
private int mFieldsRemovedCount;
}
public java.lang.String getListName()
Examples:
Shows how to number paragraphs with LISTNUM fields.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// LISTNUM fields display a number that increments at each LISTNUM field.
// These fields also have a variety of options that allow us to use them to emulate numbered lists.
FieldListNum field = (FieldListNum) builder.insertField(FieldType.FIELD_LIST_NUM, true);
// Lists start counting at 1 by default, but we can set this number to a different value, such as 0.
// This field will display "0)".
field.setStartingNumber("0");
builder.writeln("Paragraph 1");
Assert.assertEquals(" LISTNUM \\s 0", field.getFieldCode());
// LISTNUM fields maintain separate counts for each list level.
// Inserting a LISTNUM field in the same paragraph as another LISTNUM field
// increases the list level instead of the count.
// The next field will continue the count we started above and display a value of "1" at list level 1.
builder.insertField(FieldType.FIELD_LIST_NUM, true);
// This field will start a count at list level 2. It will display a value of "1".
builder.insertField(FieldType.FIELD_LIST_NUM, true);
// This field will start a count at list level 3. It will display a value of "1".
// Different list levels have different formatting,
// so these fields combined will display a value of "1)a)i)".
builder.insertField(FieldType.FIELD_LIST_NUM, true);
builder.writeln("Paragraph 2");
// The next LISTNUM field that we insert will continue the count at the list level
// that the previous LISTNUM field was on.
// We can use the "ListLevel" property to jump to a different list level.
// If this LISTNUM field stayed on list level 3, it would display "ii)",
// but, since we have moved it to list level 2, it carries on the count at that level and displays "b)".
field = (FieldListNum) builder.insertField(FieldType.FIELD_LIST_NUM, true);
field.setListLevel("2");
builder.writeln("Paragraph 3");
Assert.assertEquals(" LISTNUM \\l 2", field.getFieldCode());
// We can set the ListName property to get the field to emulate a different AUTONUM field type.
// "NumberDefault" emulates AUTONUM, "OutlineDefault" emulates AUTONUMOUT,
// and "LegalDefault" emulates AUTONUMLGL fields.
// The "OutlineDefault" list name with 1 as the starting number will result in displaying "I.".
field = (FieldListNum) builder.insertField(FieldType.FIELD_LIST_NUM, true);
field.setStartingNumber("1");
field.setListName("OutlineDefault");
builder.writeln("Paragraph 4");
Assert.assertTrue(field.hasListName());
Assert.assertEquals(" LISTNUM OutlineDefault \\s 1", field.getFieldCode());
// The ListName does not carry over from the previous field, so we will need to set it for each new field.
// This field continues the count with the different list name, and displays "II.".
field = (FieldListNum) builder.insertField(FieldType.FIELD_LIST_NUM, true);
field.setListName("OutlineDefault");
builder.writeln("Paragraph 5");
doc.updateFields();
doc.save(getArtifactsDir() + "Field.LISTNUM.docx");
public void setListName(java.lang.String value)
throws java.lang.Exception
Examples:
Shows how to number paragraphs with LISTNUM fields.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// LISTNUM fields display a number that increments at each LISTNUM field.
// These fields also have a variety of options that allow us to use them to emulate numbered lists.
FieldListNum field = (FieldListNum) builder.insertField(FieldType.FIELD_LIST_NUM, true);
// Lists start counting at 1 by default, but we can set this number to a different value, such as 0.
// This field will display "0)".
field.setStartingNumber("0");
builder.writeln("Paragraph 1");
Assert.assertEquals(" LISTNUM \\s 0", field.getFieldCode());
// LISTNUM fields maintain separate counts for each list level.
// Inserting a LISTNUM field in the same paragraph as another LISTNUM field
// increases the list level instead of the count.
// The next field will continue the count we started above and display a value of "1" at list level 1.
builder.insertField(FieldType.FIELD_LIST_NUM, true);
// This field will start a count at list level 2. It will display a value of "1".
builder.insertField(FieldType.FIELD_LIST_NUM, true);
// This field will start a count at list level 3. It will display a value of "1".
// Different list levels have different formatting,
// so these fields combined will display a value of "1)a)i)".
builder.insertField(FieldType.FIELD_LIST_NUM, true);
builder.writeln("Paragraph 2");
// The next LISTNUM field that we insert will continue the count at the list level
// that the previous LISTNUM field was on.
// We can use the "ListLevel" property to jump to a different list level.
// If this LISTNUM field stayed on list level 3, it would display "ii)",
// but, since we have moved it to list level 2, it carries on the count at that level and displays "b)".
field = (FieldListNum) builder.insertField(FieldType.FIELD_LIST_NUM, true);
field.setListLevel("2");
builder.writeln("Paragraph 3");
Assert.assertEquals(" LISTNUM \\l 2", field.getFieldCode());
// We can set the ListName property to get the field to emulate a different AUTONUM field type.
// "NumberDefault" emulates AUTONUM, "OutlineDefault" emulates AUTONUMOUT,
// and "LegalDefault" emulates AUTONUMLGL fields.
// The "OutlineDefault" list name with 1 as the starting number will result in displaying "I.".
field = (FieldListNum) builder.insertField(FieldType.FIELD_LIST_NUM, true);
field.setStartingNumber("1");
field.setListName("OutlineDefault");
builder.writeln("Paragraph 4");
Assert.assertTrue(field.hasListName());
Assert.assertEquals(" LISTNUM OutlineDefault \\s 1", field.getFieldCode());
// The ListName does not carry over from the previous field, so we will need to set it for each new field.
// This field continues the count with the different list name, and displays "II.".
field = (FieldListNum) builder.insertField(FieldType.FIELD_LIST_NUM, true);
field.setListName("OutlineDefault");
builder.writeln("Paragraph 5");
doc.updateFields();
doc.save(getArtifactsDir() + "Field.LISTNUM.docx");
value - The name of the abstract numbering definition used for the numbering.java.lang.Exceptionpublic boolean hasListName()
Examples:
Shows how to number paragraphs with LISTNUM fields.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// LISTNUM fields display a number that increments at each LISTNUM field.
// These fields also have a variety of options that allow us to use them to emulate numbered lists.
FieldListNum field = (FieldListNum) builder.insertField(FieldType.FIELD_LIST_NUM, true);
// Lists start counting at 1 by default, but we can set this number to a different value, such as 0.
// This field will display "0)".
field.setStartingNumber("0");
builder.writeln("Paragraph 1");
Assert.assertEquals(" LISTNUM \\s 0", field.getFieldCode());
// LISTNUM fields maintain separate counts for each list level.
// Inserting a LISTNUM field in the same paragraph as another LISTNUM field
// increases the list level instead of the count.
// The next field will continue the count we started above and display a value of "1" at list level 1.
builder.insertField(FieldType.FIELD_LIST_NUM, true);
// This field will start a count at list level 2. It will display a value of "1".
builder.insertField(FieldType.FIELD_LIST_NUM, true);
// This field will start a count at list level 3. It will display a value of "1".
// Different list levels have different formatting,
// so these fields combined will display a value of "1)a)i)".
builder.insertField(FieldType.FIELD_LIST_NUM, true);
builder.writeln("Paragraph 2");
// The next LISTNUM field that we insert will continue the count at the list level
// that the previous LISTNUM field was on.
// We can use the "ListLevel" property to jump to a different list level.
// If this LISTNUM field stayed on list level 3, it would display "ii)",
// but, since we have moved it to list level 2, it carries on the count at that level and displays "b)".
field = (FieldListNum) builder.insertField(FieldType.FIELD_LIST_NUM, true);
field.setListLevel("2");
builder.writeln("Paragraph 3");
Assert.assertEquals(" LISTNUM \\l 2", field.getFieldCode());
// We can set the ListName property to get the field to emulate a different AUTONUM field type.
// "NumberDefault" emulates AUTONUM, "OutlineDefault" emulates AUTONUMOUT,
// and "LegalDefault" emulates AUTONUMLGL fields.
// The "OutlineDefault" list name with 1 as the starting number will result in displaying "I.".
field = (FieldListNum) builder.insertField(FieldType.FIELD_LIST_NUM, true);
field.setStartingNumber("1");
field.setListName("OutlineDefault");
builder.writeln("Paragraph 4");
Assert.assertTrue(field.hasListName());
Assert.assertEquals(" LISTNUM OutlineDefault \\s 1", field.getFieldCode());
// The ListName does not carry over from the previous field, so we will need to set it for each new field.
// This field continues the count with the different list name, and displays "II.".
field = (FieldListNum) builder.insertField(FieldType.FIELD_LIST_NUM, true);
field.setListName("OutlineDefault");
builder.writeln("Paragraph 5");
doc.updateFields();
doc.save(getArtifactsDir() + "Field.LISTNUM.docx");
public java.lang.String getListLevel()
Examples:
Shows how to number paragraphs with LISTNUM fields.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// LISTNUM fields display a number that increments at each LISTNUM field.
// These fields also have a variety of options that allow us to use them to emulate numbered lists.
FieldListNum field = (FieldListNum) builder.insertField(FieldType.FIELD_LIST_NUM, true);
// Lists start counting at 1 by default, but we can set this number to a different value, such as 0.
// This field will display "0)".
field.setStartingNumber("0");
builder.writeln("Paragraph 1");
Assert.assertEquals(" LISTNUM \\s 0", field.getFieldCode());
// LISTNUM fields maintain separate counts for each list level.
// Inserting a LISTNUM field in the same paragraph as another LISTNUM field
// increases the list level instead of the count.
// The next field will continue the count we started above and display a value of "1" at list level 1.
builder.insertField(FieldType.FIELD_LIST_NUM, true);
// This field will start a count at list level 2. It will display a value of "1".
builder.insertField(FieldType.FIELD_LIST_NUM, true);
// This field will start a count at list level 3. It will display a value of "1".
// Different list levels have different formatting,
// so these fields combined will display a value of "1)a)i)".
builder.insertField(FieldType.FIELD_LIST_NUM, true);
builder.writeln("Paragraph 2");
// The next LISTNUM field that we insert will continue the count at the list level
// that the previous LISTNUM field was on.
// We can use the "ListLevel" property to jump to a different list level.
// If this LISTNUM field stayed on list level 3, it would display "ii)",
// but, since we have moved it to list level 2, it carries on the count at that level and displays "b)".
field = (FieldListNum) builder.insertField(FieldType.FIELD_LIST_NUM, true);
field.setListLevel("2");
builder.writeln("Paragraph 3");
Assert.assertEquals(" LISTNUM \\l 2", field.getFieldCode());
// We can set the ListName property to get the field to emulate a different AUTONUM field type.
// "NumberDefault" emulates AUTONUM, "OutlineDefault" emulates AUTONUMOUT,
// and "LegalDefault" emulates AUTONUMLGL fields.
// The "OutlineDefault" list name with 1 as the starting number will result in displaying "I.".
field = (FieldListNum) builder.insertField(FieldType.FIELD_LIST_NUM, true);
field.setStartingNumber("1");
field.setListName("OutlineDefault");
builder.writeln("Paragraph 4");
Assert.assertTrue(field.hasListName());
Assert.assertEquals(" LISTNUM OutlineDefault \\s 1", field.getFieldCode());
// The ListName does not carry over from the previous field, so we will need to set it for each new field.
// This field continues the count with the different list name, and displays "II.".
field = (FieldListNum) builder.insertField(FieldType.FIELD_LIST_NUM, true);
field.setListName("OutlineDefault");
builder.writeln("Paragraph 5");
doc.updateFields();
doc.save(getArtifactsDir() + "Field.LISTNUM.docx");
public void setListLevel(java.lang.String value)
throws java.lang.Exception
Examples:
Shows how to number paragraphs with LISTNUM fields.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// LISTNUM fields display a number that increments at each LISTNUM field.
// These fields also have a variety of options that allow us to use them to emulate numbered lists.
FieldListNum field = (FieldListNum) builder.insertField(FieldType.FIELD_LIST_NUM, true);
// Lists start counting at 1 by default, but we can set this number to a different value, such as 0.
// This field will display "0)".
field.setStartingNumber("0");
builder.writeln("Paragraph 1");
Assert.assertEquals(" LISTNUM \\s 0", field.getFieldCode());
// LISTNUM fields maintain separate counts for each list level.
// Inserting a LISTNUM field in the same paragraph as another LISTNUM field
// increases the list level instead of the count.
// The next field will continue the count we started above and display a value of "1" at list level 1.
builder.insertField(FieldType.FIELD_LIST_NUM, true);
// This field will start a count at list level 2. It will display a value of "1".
builder.insertField(FieldType.FIELD_LIST_NUM, true);
// This field will start a count at list level 3. It will display a value of "1".
// Different list levels have different formatting,
// so these fields combined will display a value of "1)a)i)".
builder.insertField(FieldType.FIELD_LIST_NUM, true);
builder.writeln("Paragraph 2");
// The next LISTNUM field that we insert will continue the count at the list level
// that the previous LISTNUM field was on.
// We can use the "ListLevel" property to jump to a different list level.
// If this LISTNUM field stayed on list level 3, it would display "ii)",
// but, since we have moved it to list level 2, it carries on the count at that level and displays "b)".
field = (FieldListNum) builder.insertField(FieldType.FIELD_LIST_NUM, true);
field.setListLevel("2");
builder.writeln("Paragraph 3");
Assert.assertEquals(" LISTNUM \\l 2", field.getFieldCode());
// We can set the ListName property to get the field to emulate a different AUTONUM field type.
// "NumberDefault" emulates AUTONUM, "OutlineDefault" emulates AUTONUMOUT,
// and "LegalDefault" emulates AUTONUMLGL fields.
// The "OutlineDefault" list name with 1 as the starting number will result in displaying "I.".
field = (FieldListNum) builder.insertField(FieldType.FIELD_LIST_NUM, true);
field.setStartingNumber("1");
field.setListName("OutlineDefault");
builder.writeln("Paragraph 4");
Assert.assertTrue(field.hasListName());
Assert.assertEquals(" LISTNUM OutlineDefault \\s 1", field.getFieldCode());
// The ListName does not carry over from the previous field, so we will need to set it for each new field.
// This field continues the count with the different list name, and displays "II.".
field = (FieldListNum) builder.insertField(FieldType.FIELD_LIST_NUM, true);
field.setListName("OutlineDefault");
builder.writeln("Paragraph 5");
doc.updateFields();
doc.save(getArtifactsDir() + "Field.LISTNUM.docx");
value - The level in the list, overriding the default behavior of the field.java.lang.Exceptionpublic java.lang.String getStartingNumber()
Examples:
Shows how to number paragraphs with LISTNUM fields.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// LISTNUM fields display a number that increments at each LISTNUM field.
// These fields also have a variety of options that allow us to use them to emulate numbered lists.
FieldListNum field = (FieldListNum) builder.insertField(FieldType.FIELD_LIST_NUM, true);
// Lists start counting at 1 by default, but we can set this number to a different value, such as 0.
// This field will display "0)".
field.setStartingNumber("0");
builder.writeln("Paragraph 1");
Assert.assertEquals(" LISTNUM \\s 0", field.getFieldCode());
// LISTNUM fields maintain separate counts for each list level.
// Inserting a LISTNUM field in the same paragraph as another LISTNUM field
// increases the list level instead of the count.
// The next field will continue the count we started above and display a value of "1" at list level 1.
builder.insertField(FieldType.FIELD_LIST_NUM, true);
// This field will start a count at list level 2. It will display a value of "1".
builder.insertField(FieldType.FIELD_LIST_NUM, true);
// This field will start a count at list level 3. It will display a value of "1".
// Different list levels have different formatting,
// so these fields combined will display a value of "1)a)i)".
builder.insertField(FieldType.FIELD_LIST_NUM, true);
builder.writeln("Paragraph 2");
// The next LISTNUM field that we insert will continue the count at the list level
// that the previous LISTNUM field was on.
// We can use the "ListLevel" property to jump to a different list level.
// If this LISTNUM field stayed on list level 3, it would display "ii)",
// but, since we have moved it to list level 2, it carries on the count at that level and displays "b)".
field = (FieldListNum) builder.insertField(FieldType.FIELD_LIST_NUM, true);
field.setListLevel("2");
builder.writeln("Paragraph 3");
Assert.assertEquals(" LISTNUM \\l 2", field.getFieldCode());
// We can set the ListName property to get the field to emulate a different AUTONUM field type.
// "NumberDefault" emulates AUTONUM, "OutlineDefault" emulates AUTONUMOUT,
// and "LegalDefault" emulates AUTONUMLGL fields.
// The "OutlineDefault" list name with 1 as the starting number will result in displaying "I.".
field = (FieldListNum) builder.insertField(FieldType.FIELD_LIST_NUM, true);
field.setStartingNumber("1");
field.setListName("OutlineDefault");
builder.writeln("Paragraph 4");
Assert.assertTrue(field.hasListName());
Assert.assertEquals(" LISTNUM OutlineDefault \\s 1", field.getFieldCode());
// The ListName does not carry over from the previous field, so we will need to set it for each new field.
// This field continues the count with the different list name, and displays "II.".
field = (FieldListNum) builder.insertField(FieldType.FIELD_LIST_NUM, true);
field.setListName("OutlineDefault");
builder.writeln("Paragraph 5");
doc.updateFields();
doc.save(getArtifactsDir() + "Field.LISTNUM.docx");
public void setStartingNumber(java.lang.String value)
throws java.lang.Exception
Examples:
Shows how to number paragraphs with LISTNUM fields.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// LISTNUM fields display a number that increments at each LISTNUM field.
// These fields also have a variety of options that allow us to use them to emulate numbered lists.
FieldListNum field = (FieldListNum) builder.insertField(FieldType.FIELD_LIST_NUM, true);
// Lists start counting at 1 by default, but we can set this number to a different value, such as 0.
// This field will display "0)".
field.setStartingNumber("0");
builder.writeln("Paragraph 1");
Assert.assertEquals(" LISTNUM \\s 0", field.getFieldCode());
// LISTNUM fields maintain separate counts for each list level.
// Inserting a LISTNUM field in the same paragraph as another LISTNUM field
// increases the list level instead of the count.
// The next field will continue the count we started above and display a value of "1" at list level 1.
builder.insertField(FieldType.FIELD_LIST_NUM, true);
// This field will start a count at list level 2. It will display a value of "1".
builder.insertField(FieldType.FIELD_LIST_NUM, true);
// This field will start a count at list level 3. It will display a value of "1".
// Different list levels have different formatting,
// so these fields combined will display a value of "1)a)i)".
builder.insertField(FieldType.FIELD_LIST_NUM, true);
builder.writeln("Paragraph 2");
// The next LISTNUM field that we insert will continue the count at the list level
// that the previous LISTNUM field was on.
// We can use the "ListLevel" property to jump to a different list level.
// If this LISTNUM field stayed on list level 3, it would display "ii)",
// but, since we have moved it to list level 2, it carries on the count at that level and displays "b)".
field = (FieldListNum) builder.insertField(FieldType.FIELD_LIST_NUM, true);
field.setListLevel("2");
builder.writeln("Paragraph 3");
Assert.assertEquals(" LISTNUM \\l 2", field.getFieldCode());
// We can set the ListName property to get the field to emulate a different AUTONUM field type.
// "NumberDefault" emulates AUTONUM, "OutlineDefault" emulates AUTONUMOUT,
// and "LegalDefault" emulates AUTONUMLGL fields.
// The "OutlineDefault" list name with 1 as the starting number will result in displaying "I.".
field = (FieldListNum) builder.insertField(FieldType.FIELD_LIST_NUM, true);
field.setStartingNumber("1");
field.setListName("OutlineDefault");
builder.writeln("Paragraph 4");
Assert.assertTrue(field.hasListName());
Assert.assertEquals(" LISTNUM OutlineDefault \\s 1", field.getFieldCode());
// The ListName does not carry over from the previous field, so we will need to set it for each new field.
// This field continues the count with the different list name, and displays "II.".
field = (FieldListNum) builder.insertField(FieldType.FIELD_LIST_NUM, true);
field.setListName("OutlineDefault");
builder.writeln("Paragraph 5");
doc.updateFields();
doc.save(getArtifactsDir() + "Field.LISTNUM.docx");
value - The starting value for this field.java.lang.Exceptionpublic int getSwitchType(java.lang.String switchName)