public class FieldSeq extends Field
To learn more, visit the Working with Fields documentation article.
Remarks:
Sequentially numbers chapters, tables, figures, and other user-defined lists of items in a document.
Examples:
Shows create numbering using SEQ fields.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// SEQ fields display a count that increments at each SEQ field.
// These fields also maintain separate counts for each unique named sequence
// identified by the SEQ field's "SequenceIdentifier" property.
// Insert a SEQ field that will display the current count value of "MySequence",
// after using the "ResetNumber" property to set it to 100.
builder.write("#");
FieldSeq fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("MySequence");
fieldSeq.setResetNumber("100");
fieldSeq.update();
Assert.assertEquals(" SEQ MySequence \\r 100", fieldSeq.getFieldCode());
Assert.assertEquals("100", fieldSeq.getResult());
// Display the next number in this sequence with another SEQ field.
builder.write(", #");
fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("MySequence");
fieldSeq.update();
Assert.assertEquals("101", fieldSeq.getResult());
// Insert a level 1 heading.
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
builder.getParagraphFormat().setStyle(doc.getStyles().get("Heading 1"));
builder.writeln("This level 1 heading will reset MySequence to 1");
builder.getParagraphFormat().setStyle(doc.getStyles().get("Normal"));
// Insert another SEQ field from the same sequence and configure it to reset the count at every heading with 1.
builder.write("\n#");
fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("MySequence");
fieldSeq.setResetHeadingLevel("1");
fieldSeq.update();
// The above heading is a level 1 heading, so the count for this sequence is reset to 1.
Assert.assertEquals(" SEQ MySequence \\s 1", fieldSeq.getFieldCode());
Assert.assertEquals("1", fieldSeq.getResult());
// Move to the next number of this sequence.
builder.write(", #");
fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("MySequence");
fieldSeq.setInsertNextNumber(true);
fieldSeq.update();
Assert.assertEquals(" SEQ MySequence \\n", fieldSeq.getFieldCode());
Assert.assertEquals("2", fieldSeq.getResult());
doc.updateFields();
doc.save(getArtifactsDir() + "Field.SEQ.ResetNumbering.docx");
Shows how to combine table of contents and sequence fields.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// A TOC field can create an entry in its table of contents for each SEQ field found in the document.
// Each entry contains the paragraph that contains the SEQ field,
// and the number of the page that the field appears on.
FieldToc fieldToc = (FieldToc) builder.insertField(FieldType.FIELD_TOC, true);
// Configure this TOC field to have a SequenceIdentifier property with a value of "MySequence".
fieldToc.setTableOfFiguresLabel("MySequence");
// Configure this TOC field to only pick up SEQ fields that are within the bounds of a bookmark
// named "TOCBookmark".
fieldToc.setBookmarkName("TOCBookmark");
builder.insertBreak(BreakType.PAGE_BREAK);
Assert.assertEquals(" TOC \\c MySequence \\b TOCBookmark", fieldToc.getFieldCode());
// SEQ fields display a count that increments at each SEQ field.
// These fields also maintain separate counts for each unique named sequence
// identified by the SEQ field's "SequenceIdentifier" property.
// Insert a SEQ field that has a sequence identifier that matches the TOC's
// TableOfFiguresLabel property. This field will not create an entry in the TOC since it is outside
// the bookmark's bounds designated by "BookmarkName".
builder.write("MySequence #");
FieldSeq fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("MySequence");
builder.writeln(", will not show up in the TOC because it is outside of the bookmark.");
builder.startBookmark("TOCBookmark");
// This SEQ field's sequence matches the TOC's "TableOfFiguresLabel" property and is within the bookmark's bounds.
// The paragraph that contains this field will show up in the TOC as an entry.
builder.write("MySequence #");
fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("MySequence");
builder.writeln(", will show up in the TOC next to the entry for the above caption.");
// This SEQ field's sequence does not match the TOC's "TableOfFiguresLabel" property,
// and is within the bounds of the bookmark. Its paragraph will not show up in the TOC as an entry.
builder.write("MySequence #");
fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("OtherSequence");
builder.writeln(", will not show up in the TOC because it's from a different sequence identifier.");
// This SEQ field's sequence matches the TOC's "TableOfFiguresLabel" property and is within the bounds of the bookmark.
// This field also references another bookmark. The contents of that bookmark will appear in the TOC entry for this SEQ field.
// The SEQ field itself will not display the contents of that bookmark.
fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("MySequence");
fieldSeq.setBookmarkName("SEQBookmark");
Assert.assertEquals(" SEQ MySequence SEQBookmark", fieldSeq.getFieldCode());
// Create a bookmark with contents that will show up in the TOC entry due to the above SEQ field referencing it.
builder.insertBreak(BreakType.PAGE_BREAK);
builder.startBookmark("SEQBookmark");
builder.write("MySequence #");
fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("MySequence");
builder.writeln(", text from inside SEQBookmark.");
builder.endBookmark("SEQBookmark");
builder.endBookmark("TOCBookmark");
doc.updateFields();
doc.save(getArtifactsDir() + "Field.SEQ.Bookmark.docx");
Shows how to populate a TOC field with entries using SEQ fields.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// A TOC field can create an entry in its table of contents for each SEQ field found in the document.
// Each entry contains the paragraph that includes the SEQ field and the page's number that the field appears on.
FieldToc fieldToc = (FieldToc) builder.insertField(FieldType.FIELD_TOC, true);
// SEQ fields display a count that increments at each SEQ field.
// These fields also maintain separate counts for each unique named sequence
// identified by the SEQ field's "SequenceIdentifier" property.
// Use the "TableOfFiguresLabel" property to name a main sequence for the TOC.
// Now, this TOC will only create entries out of SEQ fields with their "SequenceIdentifier" set to "MySequence".
fieldToc.setTableOfFiguresLabel("MySequence");
// We can name another SEQ field sequence in the "PrefixedSequenceIdentifier" property.
// SEQ fields from this prefix sequence will not create TOC entries.
// Every TOC entry created from a main sequence SEQ field will now also display the count that
// the prefix sequence is currently on at the primary sequence SEQ field that made the entry.
fieldToc.setPrefixedSequenceIdentifier("PrefixSequence");
// Each TOC entry will display the prefix sequence count immediately to the left
// of the page number that the main sequence SEQ field appears on.
// We can specify a custom separator that will appear between these two numbers.
fieldToc.setSequenceSeparator(">");
Assert.assertEquals(" TOC \\c MySequence \\s PrefixSequence \\d >", fieldToc.getFieldCode());
builder.insertBreak(BreakType.PAGE_BREAK);
// There are two ways of using SEQ fields to populate this TOC.
// 1 - Inserting a SEQ field that belongs to the TOC's prefix sequence:
// This field will increment the SEQ sequence count for the "PrefixSequence" by 1.
// Since this field does not belong to the main sequence identified
// by the "TableOfFiguresLabel" property of the TOC, it will not appear as an entry.
FieldSeq fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("PrefixSequence");
builder.insertParagraph();
Assert.assertEquals(" SEQ PrefixSequence", fieldSeq.getFieldCode());
// 2 - Inserting a SEQ field that belongs to the TOC's main sequence:
// This SEQ field will create an entry in the TOC.
// The TOC entry will contain the paragraph that the SEQ field is in and the number of the page that it appears on.
// This entry will also display the count that the prefix sequence is currently at,
// separated from the page number by the value in the TOC's SeqenceSeparator property.
// The "PrefixSequence" count is at 1, this main sequence SEQ field is on page 2,
// and the separator is ">", so entry will display "1>2".
builder.write("First TOC entry, MySequence #");
fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("MySequence");
Assert.assertEquals(" SEQ MySequence", fieldSeq.getFieldCode());
// Insert a page, advance the prefix sequence by 2, and insert a SEQ field to create a TOC entry afterwards.
// The prefix sequence is now at 2, and the main sequence SEQ field is on page 3,
// so the TOC entry will display "2>3" at its page count.
builder.insertBreak(BreakType.PAGE_BREAK);
fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("PrefixSequence");
builder.insertParagraph();
fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
builder.write("Second TOC entry, MySequence #");
fieldSeq.setSequenceIdentifier("MySequence");
doc.updateFields();
doc.save(getArtifactsDir() + "Field.TOC.SEQ.docx");
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
getBookmarkName()
Gets a bookmark name that refers to an item elsewhere in the document rather than in the current location.
|
boolean |
getInsertNextNumber()
Gets whether to insert the next sequence number for the specified item.
|
java.lang.String |
getResetHeadingLevel()
Gets an integer number representing a heading level to reset the sequence number to.
|
java.lang.String |
getResetNumber()
Gets an integer number to reset the sequence number to.
|
java.lang.String |
getSequenceIdentifier()
Gets the name assigned to the series of items that are to be numbered.
|
int |
getSwitchType(java.lang.String switchName) |
void |
setBookmarkName(java.lang.String value)
Sets a bookmark name that refers to an item elsewhere in the document rather than in the current location.
|
void |
setInsertNextNumber(boolean value)
Sets whether to insert the next sequence number for the specified item.
|
void |
setResetHeadingLevel(java.lang.String value)
Sets an integer number representing a heading level to reset the sequence number to.
|
void |
setResetNumber(java.lang.String value)
Sets an integer number to reset the sequence number to.
|
void |
setSequenceIdentifier(java.lang.String value)
Sets the name assigned to the series of items that are to be numbered.
|
getDisplayResult, getEnd, getFieldCode, getFieldCode, getFormat, getLocaleId, getResult, getSeparator, getStart, getType, isDirty, isDirty, isLocked, isLocked, needStoreOldResultNodes, remove, setLocaleId, setResult, unlink, update, updatepublic java.lang.String getSequenceIdentifier()
Examples:
Shows create numbering using SEQ fields.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// SEQ fields display a count that increments at each SEQ field.
// These fields also maintain separate counts for each unique named sequence
// identified by the SEQ field's "SequenceIdentifier" property.
// Insert a SEQ field that will display the current count value of "MySequence",
// after using the "ResetNumber" property to set it to 100.
builder.write("#");
FieldSeq fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("MySequence");
fieldSeq.setResetNumber("100");
fieldSeq.update();
Assert.assertEquals(" SEQ MySequence \\r 100", fieldSeq.getFieldCode());
Assert.assertEquals("100", fieldSeq.getResult());
// Display the next number in this sequence with another SEQ field.
builder.write(", #");
fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("MySequence");
fieldSeq.update();
Assert.assertEquals("101", fieldSeq.getResult());
// Insert a level 1 heading.
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
builder.getParagraphFormat().setStyle(doc.getStyles().get("Heading 1"));
builder.writeln("This level 1 heading will reset MySequence to 1");
builder.getParagraphFormat().setStyle(doc.getStyles().get("Normal"));
// Insert another SEQ field from the same sequence and configure it to reset the count at every heading with 1.
builder.write("\n#");
fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("MySequence");
fieldSeq.setResetHeadingLevel("1");
fieldSeq.update();
// The above heading is a level 1 heading, so the count for this sequence is reset to 1.
Assert.assertEquals(" SEQ MySequence \\s 1", fieldSeq.getFieldCode());
Assert.assertEquals("1", fieldSeq.getResult());
// Move to the next number of this sequence.
builder.write(", #");
fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("MySequence");
fieldSeq.setInsertNextNumber(true);
fieldSeq.update();
Assert.assertEquals(" SEQ MySequence \\n", fieldSeq.getFieldCode());
Assert.assertEquals("2", fieldSeq.getResult());
doc.updateFields();
doc.save(getArtifactsDir() + "Field.SEQ.ResetNumbering.docx");
Shows how to populate a TOC field with entries using SEQ fields.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// A TOC field can create an entry in its table of contents for each SEQ field found in the document.
// Each entry contains the paragraph that includes the SEQ field and the page's number that the field appears on.
FieldToc fieldToc = (FieldToc) builder.insertField(FieldType.FIELD_TOC, true);
// SEQ fields display a count that increments at each SEQ field.
// These fields also maintain separate counts for each unique named sequence
// identified by the SEQ field's "SequenceIdentifier" property.
// Use the "TableOfFiguresLabel" property to name a main sequence for the TOC.
// Now, this TOC will only create entries out of SEQ fields with their "SequenceIdentifier" set to "MySequence".
fieldToc.setTableOfFiguresLabel("MySequence");
// We can name another SEQ field sequence in the "PrefixedSequenceIdentifier" property.
// SEQ fields from this prefix sequence will not create TOC entries.
// Every TOC entry created from a main sequence SEQ field will now also display the count that
// the prefix sequence is currently on at the primary sequence SEQ field that made the entry.
fieldToc.setPrefixedSequenceIdentifier("PrefixSequence");
// Each TOC entry will display the prefix sequence count immediately to the left
// of the page number that the main sequence SEQ field appears on.
// We can specify a custom separator that will appear between these two numbers.
fieldToc.setSequenceSeparator(">");
Assert.assertEquals(" TOC \\c MySequence \\s PrefixSequence \\d >", fieldToc.getFieldCode());
builder.insertBreak(BreakType.PAGE_BREAK);
// There are two ways of using SEQ fields to populate this TOC.
// 1 - Inserting a SEQ field that belongs to the TOC's prefix sequence:
// This field will increment the SEQ sequence count for the "PrefixSequence" by 1.
// Since this field does not belong to the main sequence identified
// by the "TableOfFiguresLabel" property of the TOC, it will not appear as an entry.
FieldSeq fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("PrefixSequence");
builder.insertParagraph();
Assert.assertEquals(" SEQ PrefixSequence", fieldSeq.getFieldCode());
// 2 - Inserting a SEQ field that belongs to the TOC's main sequence:
// This SEQ field will create an entry in the TOC.
// The TOC entry will contain the paragraph that the SEQ field is in and the number of the page that it appears on.
// This entry will also display the count that the prefix sequence is currently at,
// separated from the page number by the value in the TOC's SeqenceSeparator property.
// The "PrefixSequence" count is at 1, this main sequence SEQ field is on page 2,
// and the separator is ">", so entry will display "1>2".
builder.write("First TOC entry, MySequence #");
fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("MySequence");
Assert.assertEquals(" SEQ MySequence", fieldSeq.getFieldCode());
// Insert a page, advance the prefix sequence by 2, and insert a SEQ field to create a TOC entry afterwards.
// The prefix sequence is now at 2, and the main sequence SEQ field is on page 3,
// so the TOC entry will display "2>3" at its page count.
builder.insertBreak(BreakType.PAGE_BREAK);
fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("PrefixSequence");
builder.insertParagraph();
fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
builder.write("Second TOC entry, MySequence #");
fieldSeq.setSequenceIdentifier("MySequence");
doc.updateFields();
doc.save(getArtifactsDir() + "Field.TOC.SEQ.docx");
public void setSequenceIdentifier(java.lang.String value)
throws java.lang.Exception
Examples:
Shows create numbering using SEQ fields.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// SEQ fields display a count that increments at each SEQ field.
// These fields also maintain separate counts for each unique named sequence
// identified by the SEQ field's "SequenceIdentifier" property.
// Insert a SEQ field that will display the current count value of "MySequence",
// after using the "ResetNumber" property to set it to 100.
builder.write("#");
FieldSeq fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("MySequence");
fieldSeq.setResetNumber("100");
fieldSeq.update();
Assert.assertEquals(" SEQ MySequence \\r 100", fieldSeq.getFieldCode());
Assert.assertEquals("100", fieldSeq.getResult());
// Display the next number in this sequence with another SEQ field.
builder.write(", #");
fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("MySequence");
fieldSeq.update();
Assert.assertEquals("101", fieldSeq.getResult());
// Insert a level 1 heading.
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
builder.getParagraphFormat().setStyle(doc.getStyles().get("Heading 1"));
builder.writeln("This level 1 heading will reset MySequence to 1");
builder.getParagraphFormat().setStyle(doc.getStyles().get("Normal"));
// Insert another SEQ field from the same sequence and configure it to reset the count at every heading with 1.
builder.write("\n#");
fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("MySequence");
fieldSeq.setResetHeadingLevel("1");
fieldSeq.update();
// The above heading is a level 1 heading, so the count for this sequence is reset to 1.
Assert.assertEquals(" SEQ MySequence \\s 1", fieldSeq.getFieldCode());
Assert.assertEquals("1", fieldSeq.getResult());
// Move to the next number of this sequence.
builder.write(", #");
fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("MySequence");
fieldSeq.setInsertNextNumber(true);
fieldSeq.update();
Assert.assertEquals(" SEQ MySequence \\n", fieldSeq.getFieldCode());
Assert.assertEquals("2", fieldSeq.getResult());
doc.updateFields();
doc.save(getArtifactsDir() + "Field.SEQ.ResetNumbering.docx");
Shows how to populate a TOC field with entries using SEQ fields.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// A TOC field can create an entry in its table of contents for each SEQ field found in the document.
// Each entry contains the paragraph that includes the SEQ field and the page's number that the field appears on.
FieldToc fieldToc = (FieldToc) builder.insertField(FieldType.FIELD_TOC, true);
// SEQ fields display a count that increments at each SEQ field.
// These fields also maintain separate counts for each unique named sequence
// identified by the SEQ field's "SequenceIdentifier" property.
// Use the "TableOfFiguresLabel" property to name a main sequence for the TOC.
// Now, this TOC will only create entries out of SEQ fields with their "SequenceIdentifier" set to "MySequence".
fieldToc.setTableOfFiguresLabel("MySequence");
// We can name another SEQ field sequence in the "PrefixedSequenceIdentifier" property.
// SEQ fields from this prefix sequence will not create TOC entries.
// Every TOC entry created from a main sequence SEQ field will now also display the count that
// the prefix sequence is currently on at the primary sequence SEQ field that made the entry.
fieldToc.setPrefixedSequenceIdentifier("PrefixSequence");
// Each TOC entry will display the prefix sequence count immediately to the left
// of the page number that the main sequence SEQ field appears on.
// We can specify a custom separator that will appear between these two numbers.
fieldToc.setSequenceSeparator(">");
Assert.assertEquals(" TOC \\c MySequence \\s PrefixSequence \\d >", fieldToc.getFieldCode());
builder.insertBreak(BreakType.PAGE_BREAK);
// There are two ways of using SEQ fields to populate this TOC.
// 1 - Inserting a SEQ field that belongs to the TOC's prefix sequence:
// This field will increment the SEQ sequence count for the "PrefixSequence" by 1.
// Since this field does not belong to the main sequence identified
// by the "TableOfFiguresLabel" property of the TOC, it will not appear as an entry.
FieldSeq fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("PrefixSequence");
builder.insertParagraph();
Assert.assertEquals(" SEQ PrefixSequence", fieldSeq.getFieldCode());
// 2 - Inserting a SEQ field that belongs to the TOC's main sequence:
// This SEQ field will create an entry in the TOC.
// The TOC entry will contain the paragraph that the SEQ field is in and the number of the page that it appears on.
// This entry will also display the count that the prefix sequence is currently at,
// separated from the page number by the value in the TOC's SeqenceSeparator property.
// The "PrefixSequence" count is at 1, this main sequence SEQ field is on page 2,
// and the separator is ">", so entry will display "1>2".
builder.write("First TOC entry, MySequence #");
fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("MySequence");
Assert.assertEquals(" SEQ MySequence", fieldSeq.getFieldCode());
// Insert a page, advance the prefix sequence by 2, and insert a SEQ field to create a TOC entry afterwards.
// The prefix sequence is now at 2, and the main sequence SEQ field is on page 3,
// so the TOC entry will display "2>3" at its page count.
builder.insertBreak(BreakType.PAGE_BREAK);
fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("PrefixSequence");
builder.insertParagraph();
fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
builder.write("Second TOC entry, MySequence #");
fieldSeq.setSequenceIdentifier("MySequence");
doc.updateFields();
doc.save(getArtifactsDir() + "Field.TOC.SEQ.docx");
value - The name assigned to the series of items that are to be numbered.java.lang.Exceptionpublic java.lang.String getBookmarkName()
Examples:
Shows how to combine table of contents and sequence fields.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// A TOC field can create an entry in its table of contents for each SEQ field found in the document.
// Each entry contains the paragraph that contains the SEQ field,
// and the number of the page that the field appears on.
FieldToc fieldToc = (FieldToc) builder.insertField(FieldType.FIELD_TOC, true);
// Configure this TOC field to have a SequenceIdentifier property with a value of "MySequence".
fieldToc.setTableOfFiguresLabel("MySequence");
// Configure this TOC field to only pick up SEQ fields that are within the bounds of a bookmark
// named "TOCBookmark".
fieldToc.setBookmarkName("TOCBookmark");
builder.insertBreak(BreakType.PAGE_BREAK);
Assert.assertEquals(" TOC \\c MySequence \\b TOCBookmark", fieldToc.getFieldCode());
// SEQ fields display a count that increments at each SEQ field.
// These fields also maintain separate counts for each unique named sequence
// identified by the SEQ field's "SequenceIdentifier" property.
// Insert a SEQ field that has a sequence identifier that matches the TOC's
// TableOfFiguresLabel property. This field will not create an entry in the TOC since it is outside
// the bookmark's bounds designated by "BookmarkName".
builder.write("MySequence #");
FieldSeq fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("MySequence");
builder.writeln(", will not show up in the TOC because it is outside of the bookmark.");
builder.startBookmark("TOCBookmark");
// This SEQ field's sequence matches the TOC's "TableOfFiguresLabel" property and is within the bookmark's bounds.
// The paragraph that contains this field will show up in the TOC as an entry.
builder.write("MySequence #");
fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("MySequence");
builder.writeln(", will show up in the TOC next to the entry for the above caption.");
// This SEQ field's sequence does not match the TOC's "TableOfFiguresLabel" property,
// and is within the bounds of the bookmark. Its paragraph will not show up in the TOC as an entry.
builder.write("MySequence #");
fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("OtherSequence");
builder.writeln(", will not show up in the TOC because it's from a different sequence identifier.");
// This SEQ field's sequence matches the TOC's "TableOfFiguresLabel" property and is within the bounds of the bookmark.
// This field also references another bookmark. The contents of that bookmark will appear in the TOC entry for this SEQ field.
// The SEQ field itself will not display the contents of that bookmark.
fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("MySequence");
fieldSeq.setBookmarkName("SEQBookmark");
Assert.assertEquals(" SEQ MySequence SEQBookmark", fieldSeq.getFieldCode());
// Create a bookmark with contents that will show up in the TOC entry due to the above SEQ field referencing it.
builder.insertBreak(BreakType.PAGE_BREAK);
builder.startBookmark("SEQBookmark");
builder.write("MySequence #");
fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("MySequence");
builder.writeln(", text from inside SEQBookmark.");
builder.endBookmark("SEQBookmark");
builder.endBookmark("TOCBookmark");
doc.updateFields();
doc.save(getArtifactsDir() + "Field.SEQ.Bookmark.docx");
public void setBookmarkName(java.lang.String value)
throws java.lang.Exception
Examples:
Shows how to combine table of contents and sequence fields.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// A TOC field can create an entry in its table of contents for each SEQ field found in the document.
// Each entry contains the paragraph that contains the SEQ field,
// and the number of the page that the field appears on.
FieldToc fieldToc = (FieldToc) builder.insertField(FieldType.FIELD_TOC, true);
// Configure this TOC field to have a SequenceIdentifier property with a value of "MySequence".
fieldToc.setTableOfFiguresLabel("MySequence");
// Configure this TOC field to only pick up SEQ fields that are within the bounds of a bookmark
// named "TOCBookmark".
fieldToc.setBookmarkName("TOCBookmark");
builder.insertBreak(BreakType.PAGE_BREAK);
Assert.assertEquals(" TOC \\c MySequence \\b TOCBookmark", fieldToc.getFieldCode());
// SEQ fields display a count that increments at each SEQ field.
// These fields also maintain separate counts for each unique named sequence
// identified by the SEQ field's "SequenceIdentifier" property.
// Insert a SEQ field that has a sequence identifier that matches the TOC's
// TableOfFiguresLabel property. This field will not create an entry in the TOC since it is outside
// the bookmark's bounds designated by "BookmarkName".
builder.write("MySequence #");
FieldSeq fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("MySequence");
builder.writeln(", will not show up in the TOC because it is outside of the bookmark.");
builder.startBookmark("TOCBookmark");
// This SEQ field's sequence matches the TOC's "TableOfFiguresLabel" property and is within the bookmark's bounds.
// The paragraph that contains this field will show up in the TOC as an entry.
builder.write("MySequence #");
fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("MySequence");
builder.writeln(", will show up in the TOC next to the entry for the above caption.");
// This SEQ field's sequence does not match the TOC's "TableOfFiguresLabel" property,
// and is within the bounds of the bookmark. Its paragraph will not show up in the TOC as an entry.
builder.write("MySequence #");
fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("OtherSequence");
builder.writeln(", will not show up in the TOC because it's from a different sequence identifier.");
// This SEQ field's sequence matches the TOC's "TableOfFiguresLabel" property and is within the bounds of the bookmark.
// This field also references another bookmark. The contents of that bookmark will appear in the TOC entry for this SEQ field.
// The SEQ field itself will not display the contents of that bookmark.
fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("MySequence");
fieldSeq.setBookmarkName("SEQBookmark");
Assert.assertEquals(" SEQ MySequence SEQBookmark", fieldSeq.getFieldCode());
// Create a bookmark with contents that will show up in the TOC entry due to the above SEQ field referencing it.
builder.insertBreak(BreakType.PAGE_BREAK);
builder.startBookmark("SEQBookmark");
builder.write("MySequence #");
fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("MySequence");
builder.writeln(", text from inside SEQBookmark.");
builder.endBookmark("SEQBookmark");
builder.endBookmark("TOCBookmark");
doc.updateFields();
doc.save(getArtifactsDir() + "Field.SEQ.Bookmark.docx");
value - A bookmark name that refers to an item elsewhere in the document rather than in the current location.java.lang.Exceptionpublic boolean getInsertNextNumber()
Examples:
Shows create numbering using SEQ fields.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// SEQ fields display a count that increments at each SEQ field.
// These fields also maintain separate counts for each unique named sequence
// identified by the SEQ field's "SequenceIdentifier" property.
// Insert a SEQ field that will display the current count value of "MySequence",
// after using the "ResetNumber" property to set it to 100.
builder.write("#");
FieldSeq fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("MySequence");
fieldSeq.setResetNumber("100");
fieldSeq.update();
Assert.assertEquals(" SEQ MySequence \\r 100", fieldSeq.getFieldCode());
Assert.assertEquals("100", fieldSeq.getResult());
// Display the next number in this sequence with another SEQ field.
builder.write(", #");
fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("MySequence");
fieldSeq.update();
Assert.assertEquals("101", fieldSeq.getResult());
// Insert a level 1 heading.
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
builder.getParagraphFormat().setStyle(doc.getStyles().get("Heading 1"));
builder.writeln("This level 1 heading will reset MySequence to 1");
builder.getParagraphFormat().setStyle(doc.getStyles().get("Normal"));
// Insert another SEQ field from the same sequence and configure it to reset the count at every heading with 1.
builder.write("\n#");
fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("MySequence");
fieldSeq.setResetHeadingLevel("1");
fieldSeq.update();
// The above heading is a level 1 heading, so the count for this sequence is reset to 1.
Assert.assertEquals(" SEQ MySequence \\s 1", fieldSeq.getFieldCode());
Assert.assertEquals("1", fieldSeq.getResult());
// Move to the next number of this sequence.
builder.write(", #");
fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("MySequence");
fieldSeq.setInsertNextNumber(true);
fieldSeq.update();
Assert.assertEquals(" SEQ MySequence \\n", fieldSeq.getFieldCode());
Assert.assertEquals("2", fieldSeq.getResult());
doc.updateFields();
doc.save(getArtifactsDir() + "Field.SEQ.ResetNumbering.docx");
public void setInsertNextNumber(boolean value)
throws java.lang.Exception
Examples:
Shows create numbering using SEQ fields.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// SEQ fields display a count that increments at each SEQ field.
// These fields also maintain separate counts for each unique named sequence
// identified by the SEQ field's "SequenceIdentifier" property.
// Insert a SEQ field that will display the current count value of "MySequence",
// after using the "ResetNumber" property to set it to 100.
builder.write("#");
FieldSeq fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("MySequence");
fieldSeq.setResetNumber("100");
fieldSeq.update();
Assert.assertEquals(" SEQ MySequence \\r 100", fieldSeq.getFieldCode());
Assert.assertEquals("100", fieldSeq.getResult());
// Display the next number in this sequence with another SEQ field.
builder.write(", #");
fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("MySequence");
fieldSeq.update();
Assert.assertEquals("101", fieldSeq.getResult());
// Insert a level 1 heading.
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
builder.getParagraphFormat().setStyle(doc.getStyles().get("Heading 1"));
builder.writeln("This level 1 heading will reset MySequence to 1");
builder.getParagraphFormat().setStyle(doc.getStyles().get("Normal"));
// Insert another SEQ field from the same sequence and configure it to reset the count at every heading with 1.
builder.write("\n#");
fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("MySequence");
fieldSeq.setResetHeadingLevel("1");
fieldSeq.update();
// The above heading is a level 1 heading, so the count for this sequence is reset to 1.
Assert.assertEquals(" SEQ MySequence \\s 1", fieldSeq.getFieldCode());
Assert.assertEquals("1", fieldSeq.getResult());
// Move to the next number of this sequence.
builder.write(", #");
fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("MySequence");
fieldSeq.setInsertNextNumber(true);
fieldSeq.update();
Assert.assertEquals(" SEQ MySequence \\n", fieldSeq.getFieldCode());
Assert.assertEquals("2", fieldSeq.getResult());
doc.updateFields();
doc.save(getArtifactsDir() + "Field.SEQ.ResetNumbering.docx");
value - Whether to insert the next sequence number for the specified item.java.lang.Exceptionpublic java.lang.String getResetNumber()
Examples:
Shows create numbering using SEQ fields.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// SEQ fields display a count that increments at each SEQ field.
// These fields also maintain separate counts for each unique named sequence
// identified by the SEQ field's "SequenceIdentifier" property.
// Insert a SEQ field that will display the current count value of "MySequence",
// after using the "ResetNumber" property to set it to 100.
builder.write("#");
FieldSeq fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("MySequence");
fieldSeq.setResetNumber("100");
fieldSeq.update();
Assert.assertEquals(" SEQ MySequence \\r 100", fieldSeq.getFieldCode());
Assert.assertEquals("100", fieldSeq.getResult());
// Display the next number in this sequence with another SEQ field.
builder.write(", #");
fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("MySequence");
fieldSeq.update();
Assert.assertEquals("101", fieldSeq.getResult());
// Insert a level 1 heading.
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
builder.getParagraphFormat().setStyle(doc.getStyles().get("Heading 1"));
builder.writeln("This level 1 heading will reset MySequence to 1");
builder.getParagraphFormat().setStyle(doc.getStyles().get("Normal"));
// Insert another SEQ field from the same sequence and configure it to reset the count at every heading with 1.
builder.write("\n#");
fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("MySequence");
fieldSeq.setResetHeadingLevel("1");
fieldSeq.update();
// The above heading is a level 1 heading, so the count for this sequence is reset to 1.
Assert.assertEquals(" SEQ MySequence \\s 1", fieldSeq.getFieldCode());
Assert.assertEquals("1", fieldSeq.getResult());
// Move to the next number of this sequence.
builder.write(", #");
fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("MySequence");
fieldSeq.setInsertNextNumber(true);
fieldSeq.update();
Assert.assertEquals(" SEQ MySequence \\n", fieldSeq.getFieldCode());
Assert.assertEquals("2", fieldSeq.getResult());
doc.updateFields();
doc.save(getArtifactsDir() + "Field.SEQ.ResetNumbering.docx");
public void setResetNumber(java.lang.String value)
throws java.lang.Exception
Examples:
Shows create numbering using SEQ fields.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// SEQ fields display a count that increments at each SEQ field.
// These fields also maintain separate counts for each unique named sequence
// identified by the SEQ field's "SequenceIdentifier" property.
// Insert a SEQ field that will display the current count value of "MySequence",
// after using the "ResetNumber" property to set it to 100.
builder.write("#");
FieldSeq fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("MySequence");
fieldSeq.setResetNumber("100");
fieldSeq.update();
Assert.assertEquals(" SEQ MySequence \\r 100", fieldSeq.getFieldCode());
Assert.assertEquals("100", fieldSeq.getResult());
// Display the next number in this sequence with another SEQ field.
builder.write(", #");
fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("MySequence");
fieldSeq.update();
Assert.assertEquals("101", fieldSeq.getResult());
// Insert a level 1 heading.
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
builder.getParagraphFormat().setStyle(doc.getStyles().get("Heading 1"));
builder.writeln("This level 1 heading will reset MySequence to 1");
builder.getParagraphFormat().setStyle(doc.getStyles().get("Normal"));
// Insert another SEQ field from the same sequence and configure it to reset the count at every heading with 1.
builder.write("\n#");
fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("MySequence");
fieldSeq.setResetHeadingLevel("1");
fieldSeq.update();
// The above heading is a level 1 heading, so the count for this sequence is reset to 1.
Assert.assertEquals(" SEQ MySequence \\s 1", fieldSeq.getFieldCode());
Assert.assertEquals("1", fieldSeq.getResult());
// Move to the next number of this sequence.
builder.write(", #");
fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("MySequence");
fieldSeq.setInsertNextNumber(true);
fieldSeq.update();
Assert.assertEquals(" SEQ MySequence \\n", fieldSeq.getFieldCode());
Assert.assertEquals("2", fieldSeq.getResult());
doc.updateFields();
doc.save(getArtifactsDir() + "Field.SEQ.ResetNumbering.docx");
value - An integer number to reset the sequence number to.java.lang.Exceptionpublic java.lang.String getResetHeadingLevel()
Examples:
Shows create numbering using SEQ fields.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// SEQ fields display a count that increments at each SEQ field.
// These fields also maintain separate counts for each unique named sequence
// identified by the SEQ field's "SequenceIdentifier" property.
// Insert a SEQ field that will display the current count value of "MySequence",
// after using the "ResetNumber" property to set it to 100.
builder.write("#");
FieldSeq fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("MySequence");
fieldSeq.setResetNumber("100");
fieldSeq.update();
Assert.assertEquals(" SEQ MySequence \\r 100", fieldSeq.getFieldCode());
Assert.assertEquals("100", fieldSeq.getResult());
// Display the next number in this sequence with another SEQ field.
builder.write(", #");
fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("MySequence");
fieldSeq.update();
Assert.assertEquals("101", fieldSeq.getResult());
// Insert a level 1 heading.
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
builder.getParagraphFormat().setStyle(doc.getStyles().get("Heading 1"));
builder.writeln("This level 1 heading will reset MySequence to 1");
builder.getParagraphFormat().setStyle(doc.getStyles().get("Normal"));
// Insert another SEQ field from the same sequence and configure it to reset the count at every heading with 1.
builder.write("\n#");
fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("MySequence");
fieldSeq.setResetHeadingLevel("1");
fieldSeq.update();
// The above heading is a level 1 heading, so the count for this sequence is reset to 1.
Assert.assertEquals(" SEQ MySequence \\s 1", fieldSeq.getFieldCode());
Assert.assertEquals("1", fieldSeq.getResult());
// Move to the next number of this sequence.
builder.write(", #");
fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("MySequence");
fieldSeq.setInsertNextNumber(true);
fieldSeq.update();
Assert.assertEquals(" SEQ MySequence \\n", fieldSeq.getFieldCode());
Assert.assertEquals("2", fieldSeq.getResult());
doc.updateFields();
doc.save(getArtifactsDir() + "Field.SEQ.ResetNumbering.docx");
public void setResetHeadingLevel(java.lang.String value)
throws java.lang.Exception
Examples:
Shows create numbering using SEQ fields.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// SEQ fields display a count that increments at each SEQ field.
// These fields also maintain separate counts for each unique named sequence
// identified by the SEQ field's "SequenceIdentifier" property.
// Insert a SEQ field that will display the current count value of "MySequence",
// after using the "ResetNumber" property to set it to 100.
builder.write("#");
FieldSeq fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("MySequence");
fieldSeq.setResetNumber("100");
fieldSeq.update();
Assert.assertEquals(" SEQ MySequence \\r 100", fieldSeq.getFieldCode());
Assert.assertEquals("100", fieldSeq.getResult());
// Display the next number in this sequence with another SEQ field.
builder.write(", #");
fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("MySequence");
fieldSeq.update();
Assert.assertEquals("101", fieldSeq.getResult());
// Insert a level 1 heading.
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
builder.getParagraphFormat().setStyle(doc.getStyles().get("Heading 1"));
builder.writeln("This level 1 heading will reset MySequence to 1");
builder.getParagraphFormat().setStyle(doc.getStyles().get("Normal"));
// Insert another SEQ field from the same sequence and configure it to reset the count at every heading with 1.
builder.write("\n#");
fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("MySequence");
fieldSeq.setResetHeadingLevel("1");
fieldSeq.update();
// The above heading is a level 1 heading, so the count for this sequence is reset to 1.
Assert.assertEquals(" SEQ MySequence \\s 1", fieldSeq.getFieldCode());
Assert.assertEquals("1", fieldSeq.getResult());
// Move to the next number of this sequence.
builder.write(", #");
fieldSeq = (FieldSeq) builder.insertField(FieldType.FIELD_SEQUENCE, true);
fieldSeq.setSequenceIdentifier("MySequence");
fieldSeq.setInsertNextNumber(true);
fieldSeq.update();
Assert.assertEquals(" SEQ MySequence \\n", fieldSeq.getFieldCode());
Assert.assertEquals("2", fieldSeq.getResult());
doc.updateFields();
doc.save(getArtifactsDir() + "Field.SEQ.ResetNumbering.docx");
value - An integer number representing a heading level to reset the sequence number to.java.lang.Exceptionpublic int getSwitchType(java.lang.String switchName)