public class FieldXE extends Field
To learn more, visit the Working with Fields documentation article.
Remarks:
Defines the text and page number for an index entry, which is used by an INDEX field.
Examples:
Shows how to create an INDEX field, and then use XE fields to populate it with entries.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Create an INDEX field which will display an entry for each XE field found in the document.
// Each entry will display the XE field's Text property value on the left side
// and the page containing the XE field on the right.
// If the XE fields have the same value in their "Text" property,
// the INDEX field will group them into one entry.
FieldIndex index = (FieldIndex) builder.insertField(FieldType.FIELD_INDEX, true);
// Configure the INDEX field only to display XE fields that are within the bounds
// of a bookmark named "MainBookmark", and whose "EntryType" properties have a value of "A".
// For both INDEX and XE fields, the "EntryType" property only uses the first character of its string value.
index.setBookmarkName("MainBookmark");
index.setEntryType("A");
Assert.assertEquals(" INDEX \\b MainBookmark \\f A", index.getFieldCode());
// On a new page, start the bookmark with a name that matches the value
// of the INDEX field's "BookmarkName" property.
builder.insertBreak(BreakType.PAGE_BREAK);
builder.startBookmark("MainBookmark");
// The INDEX field will pick up this entry because it is inside the bookmark,
// and its entry type also matches the INDEX field's entry type.
FieldXE indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Index entry 1");
indexEntry.setEntryType("A");
Assert.assertEquals(" XE \"Index entry 1\" \\f A", indexEntry.getFieldCode());
// Insert an XE field that will not appear in the INDEX because the entry types do not match.
builder.insertBreak(BreakType.PAGE_BREAK);
indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Index entry 2");
indexEntry.setEntryType("B");
// End the bookmark and insert an XE field afterwards.
// It is of the same type as the INDEX field, but will not appear
// since it is outside the bookmark's boundaries.
builder.endBookmark("MainBookmark");
builder.insertBreak(BreakType.PAGE_BREAK);
indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Index entry 3");
indexEntry.setEntryType("A");
doc.updatePageLayout();
doc.updateFields();
doc.save(getArtifactsDir() + "Field.INDEX.XE.Filtering.docx");
Shows how to populate an INDEX field with entries using XE fields, and also modify its appearance.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Create an INDEX field which will display an entry for each XE field found in the document.
// Each entry will display the XE field's Text property value on the left side,
// and the number of the page that contains the XE field on the right.
// If the XE fields have the same value in their "Text" property,
// the INDEX field will group them into one entry.
FieldIndex index = (FieldIndex) builder.insertField(FieldType.FIELD_INDEX, true);
index.setLanguageId("1033");
// Setting this property's value to "A" will group all the entries by their first letter,
// and place that letter in uppercase above each group.
index.setHeading("A");
// Set the table created by the INDEX field to span over 2 columns.
index.setNumberOfColumns("2");
// Set any entries with starting letters outside the "a-c" character range to be omitted.
index.setLetterRange("a-c");
Assert.assertEquals(" INDEX \\z 1033 \\h A \\c 2 \\p a-c", index.getFieldCode());
// These next two XE fields will show up under the "A" heading,
// with their respective text stylings also applied to their page numbers.
builder.insertBreak(BreakType.PAGE_BREAK);
FieldXE indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Apple");
indexEntry.isItalic(true);
Assert.assertEquals(" XE Apple \\i", indexEntry.getFieldCode());
builder.insertBreak(BreakType.PAGE_BREAK);
indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Apricot");
indexEntry.isBold(true);
Assert.assertEquals(" XE Apricot \\b", indexEntry.getFieldCode());
// Both the next two XE fields will be under a "B" and "C" heading in the INDEX fields table of contents.
builder.insertBreak(BreakType.PAGE_BREAK);
indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Banana");
builder.insertBreak(BreakType.PAGE_BREAK);
indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Cherry");
// INDEX fields sort all entries alphabetically, so this entry will show up under "A" with the other two.
builder.insertBreak(BreakType.PAGE_BREAK);
indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Avocado");
// This entry will not appear because it starts with the letter "D",
// which is outside the "a-c" character range that the INDEX field's LetterRange property defines.
builder.insertBreak(BreakType.PAGE_BREAK);
indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Durian");
doc.updatePageLayout();
doc.updateFields();
doc.save(getArtifactsDir() + "Field.INDEX.XE.Formatting.docx");
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
getEntryType()
Gets an index entry type.
|
java.lang.String |
getPageNumberReplacement()
Gets text used in place of a page number.
|
java.lang.String |
getPageRangeBookmarkName()
Gets the name of the bookmark that marks a range of pages that is inserted as the entry's page number.
|
int |
getSwitchType(java.lang.String switchName) |
java.lang.String |
getText()
Gets the text of the entry.
|
java.lang.String |
getYomi()
Gets the yomi (first phonetic character for sorting indexes) for the index entry
|
boolean |
isBold()
Gets whether to apply bold formatting to the entry's page number.
|
void |
isBold(boolean value)
Sets whether to apply bold formatting to the entry's page number.
|
boolean |
isItalic()
Gets whether to apply italic formatting to the entry's page number.
|
void |
isItalic(boolean value)
Sets whether to apply italic formatting to the entry's page number.
|
void |
setEntryType(java.lang.String value)
Sets an index entry type.
|
void |
setPageNumberReplacement(java.lang.String value)
Sets text used in place of a page number.
|
void |
setPageRangeBookmarkName(java.lang.String value)
Sets the name of the bookmark that marks a range of pages that is inserted as the entry's page number.
|
void |
setText(java.lang.String value)
Sets the text of the entry.
|
void |
setYomi(java.lang.String value)
Sets the yomi (first phonetic character for sorting indexes) for the index entry
|
getDisplayResult, getEnd, getFieldCode, getFieldCode, getFormat, getLocaleId, getResult, getSeparator, getStart, getType, isDirty, isDirty, isLocked, isLocked, needStoreOldResultNodes, remove, setLocaleId, setResult, unlink, update, updatepublic int getSwitchType(java.lang.String switchName)
public java.lang.String getText()
Examples:
Shows how to create an INDEX field, and then use XE fields to populate it with entries.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Create an INDEX field which will display an entry for each XE field found in the document.
// Each entry will display the XE field's Text property value on the left side
// and the page containing the XE field on the right.
// If the XE fields have the same value in their "Text" property,
// the INDEX field will group them into one entry.
FieldIndex index = (FieldIndex) builder.insertField(FieldType.FIELD_INDEX, true);
// Configure the INDEX field only to display XE fields that are within the bounds
// of a bookmark named "MainBookmark", and whose "EntryType" properties have a value of "A".
// For both INDEX and XE fields, the "EntryType" property only uses the first character of its string value.
index.setBookmarkName("MainBookmark");
index.setEntryType("A");
Assert.assertEquals(" INDEX \\b MainBookmark \\f A", index.getFieldCode());
// On a new page, start the bookmark with a name that matches the value
// of the INDEX field's "BookmarkName" property.
builder.insertBreak(BreakType.PAGE_BREAK);
builder.startBookmark("MainBookmark");
// The INDEX field will pick up this entry because it is inside the bookmark,
// and its entry type also matches the INDEX field's entry type.
FieldXE indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Index entry 1");
indexEntry.setEntryType("A");
Assert.assertEquals(" XE \"Index entry 1\" \\f A", indexEntry.getFieldCode());
// Insert an XE field that will not appear in the INDEX because the entry types do not match.
builder.insertBreak(BreakType.PAGE_BREAK);
indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Index entry 2");
indexEntry.setEntryType("B");
// End the bookmark and insert an XE field afterwards.
// It is of the same type as the INDEX field, but will not appear
// since it is outside the bookmark's boundaries.
builder.endBookmark("MainBookmark");
builder.insertBreak(BreakType.PAGE_BREAK);
indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Index entry 3");
indexEntry.setEntryType("A");
doc.updatePageLayout();
doc.updateFields();
doc.save(getArtifactsDir() + "Field.INDEX.XE.Filtering.docx");
Shows how to populate an INDEX field with entries using XE fields, and also modify its appearance.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Create an INDEX field which will display an entry for each XE field found in the document.
// Each entry will display the XE field's Text property value on the left side,
// and the number of the page that contains the XE field on the right.
// If the XE fields have the same value in their "Text" property,
// the INDEX field will group them into one entry.
FieldIndex index = (FieldIndex) builder.insertField(FieldType.FIELD_INDEX, true);
index.setLanguageId("1033");
// Setting this property's value to "A" will group all the entries by their first letter,
// and place that letter in uppercase above each group.
index.setHeading("A");
// Set the table created by the INDEX field to span over 2 columns.
index.setNumberOfColumns("2");
// Set any entries with starting letters outside the "a-c" character range to be omitted.
index.setLetterRange("a-c");
Assert.assertEquals(" INDEX \\z 1033 \\h A \\c 2 \\p a-c", index.getFieldCode());
// These next two XE fields will show up under the "A" heading,
// with their respective text stylings also applied to their page numbers.
builder.insertBreak(BreakType.PAGE_BREAK);
FieldXE indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Apple");
indexEntry.isItalic(true);
Assert.assertEquals(" XE Apple \\i", indexEntry.getFieldCode());
builder.insertBreak(BreakType.PAGE_BREAK);
indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Apricot");
indexEntry.isBold(true);
Assert.assertEquals(" XE Apricot \\b", indexEntry.getFieldCode());
// Both the next two XE fields will be under a "B" and "C" heading in the INDEX fields table of contents.
builder.insertBreak(BreakType.PAGE_BREAK);
indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Banana");
builder.insertBreak(BreakType.PAGE_BREAK);
indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Cherry");
// INDEX fields sort all entries alphabetically, so this entry will show up under "A" with the other two.
builder.insertBreak(BreakType.PAGE_BREAK);
indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Avocado");
// This entry will not appear because it starts with the letter "D",
// which is outside the "a-c" character range that the INDEX field's LetterRange property defines.
builder.insertBreak(BreakType.PAGE_BREAK);
indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Durian");
doc.updatePageLayout();
doc.updateFields();
doc.save(getArtifactsDir() + "Field.INDEX.XE.Formatting.docx");
public void setText(java.lang.String value)
throws java.lang.Exception
Examples:
Shows how to create an INDEX field, and then use XE fields to populate it with entries.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Create an INDEX field which will display an entry for each XE field found in the document.
// Each entry will display the XE field's Text property value on the left side
// and the page containing the XE field on the right.
// If the XE fields have the same value in their "Text" property,
// the INDEX field will group them into one entry.
FieldIndex index = (FieldIndex) builder.insertField(FieldType.FIELD_INDEX, true);
// Configure the INDEX field only to display XE fields that are within the bounds
// of a bookmark named "MainBookmark", and whose "EntryType" properties have a value of "A".
// For both INDEX and XE fields, the "EntryType" property only uses the first character of its string value.
index.setBookmarkName("MainBookmark");
index.setEntryType("A");
Assert.assertEquals(" INDEX \\b MainBookmark \\f A", index.getFieldCode());
// On a new page, start the bookmark with a name that matches the value
// of the INDEX field's "BookmarkName" property.
builder.insertBreak(BreakType.PAGE_BREAK);
builder.startBookmark("MainBookmark");
// The INDEX field will pick up this entry because it is inside the bookmark,
// and its entry type also matches the INDEX field's entry type.
FieldXE indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Index entry 1");
indexEntry.setEntryType("A");
Assert.assertEquals(" XE \"Index entry 1\" \\f A", indexEntry.getFieldCode());
// Insert an XE field that will not appear in the INDEX because the entry types do not match.
builder.insertBreak(BreakType.PAGE_BREAK);
indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Index entry 2");
indexEntry.setEntryType("B");
// End the bookmark and insert an XE field afterwards.
// It is of the same type as the INDEX field, but will not appear
// since it is outside the bookmark's boundaries.
builder.endBookmark("MainBookmark");
builder.insertBreak(BreakType.PAGE_BREAK);
indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Index entry 3");
indexEntry.setEntryType("A");
doc.updatePageLayout();
doc.updateFields();
doc.save(getArtifactsDir() + "Field.INDEX.XE.Filtering.docx");
Shows how to populate an INDEX field with entries using XE fields, and also modify its appearance.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Create an INDEX field which will display an entry for each XE field found in the document.
// Each entry will display the XE field's Text property value on the left side,
// and the number of the page that contains the XE field on the right.
// If the XE fields have the same value in their "Text" property,
// the INDEX field will group them into one entry.
FieldIndex index = (FieldIndex) builder.insertField(FieldType.FIELD_INDEX, true);
index.setLanguageId("1033");
// Setting this property's value to "A" will group all the entries by their first letter,
// and place that letter in uppercase above each group.
index.setHeading("A");
// Set the table created by the INDEX field to span over 2 columns.
index.setNumberOfColumns("2");
// Set any entries with starting letters outside the "a-c" character range to be omitted.
index.setLetterRange("a-c");
Assert.assertEquals(" INDEX \\z 1033 \\h A \\c 2 \\p a-c", index.getFieldCode());
// These next two XE fields will show up under the "A" heading,
// with their respective text stylings also applied to their page numbers.
builder.insertBreak(BreakType.PAGE_BREAK);
FieldXE indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Apple");
indexEntry.isItalic(true);
Assert.assertEquals(" XE Apple \\i", indexEntry.getFieldCode());
builder.insertBreak(BreakType.PAGE_BREAK);
indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Apricot");
indexEntry.isBold(true);
Assert.assertEquals(" XE Apricot \\b", indexEntry.getFieldCode());
// Both the next two XE fields will be under a "B" and "C" heading in the INDEX fields table of contents.
builder.insertBreak(BreakType.PAGE_BREAK);
indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Banana");
builder.insertBreak(BreakType.PAGE_BREAK);
indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Cherry");
// INDEX fields sort all entries alphabetically, so this entry will show up under "A" with the other two.
builder.insertBreak(BreakType.PAGE_BREAK);
indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Avocado");
// This entry will not appear because it starts with the letter "D",
// which is outside the "a-c" character range that the INDEX field's LetterRange property defines.
builder.insertBreak(BreakType.PAGE_BREAK);
indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Durian");
doc.updatePageLayout();
doc.updateFields();
doc.save(getArtifactsDir() + "Field.INDEX.XE.Formatting.docx");
value - The text of the entry.java.lang.Exceptionpublic boolean isBold()
Examples:
Shows how to populate an INDEX field with entries using XE fields, and also modify its appearance.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Create an INDEX field which will display an entry for each XE field found in the document.
// Each entry will display the XE field's Text property value on the left side,
// and the number of the page that contains the XE field on the right.
// If the XE fields have the same value in their "Text" property,
// the INDEX field will group them into one entry.
FieldIndex index = (FieldIndex) builder.insertField(FieldType.FIELD_INDEX, true);
index.setLanguageId("1033");
// Setting this property's value to "A" will group all the entries by their first letter,
// and place that letter in uppercase above each group.
index.setHeading("A");
// Set the table created by the INDEX field to span over 2 columns.
index.setNumberOfColumns("2");
// Set any entries with starting letters outside the "a-c" character range to be omitted.
index.setLetterRange("a-c");
Assert.assertEquals(" INDEX \\z 1033 \\h A \\c 2 \\p a-c", index.getFieldCode());
// These next two XE fields will show up under the "A" heading,
// with their respective text stylings also applied to their page numbers.
builder.insertBreak(BreakType.PAGE_BREAK);
FieldXE indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Apple");
indexEntry.isItalic(true);
Assert.assertEquals(" XE Apple \\i", indexEntry.getFieldCode());
builder.insertBreak(BreakType.PAGE_BREAK);
indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Apricot");
indexEntry.isBold(true);
Assert.assertEquals(" XE Apricot \\b", indexEntry.getFieldCode());
// Both the next two XE fields will be under a "B" and "C" heading in the INDEX fields table of contents.
builder.insertBreak(BreakType.PAGE_BREAK);
indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Banana");
builder.insertBreak(BreakType.PAGE_BREAK);
indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Cherry");
// INDEX fields sort all entries alphabetically, so this entry will show up under "A" with the other two.
builder.insertBreak(BreakType.PAGE_BREAK);
indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Avocado");
// This entry will not appear because it starts with the letter "D",
// which is outside the "a-c" character range that the INDEX field's LetterRange property defines.
builder.insertBreak(BreakType.PAGE_BREAK);
indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Durian");
doc.updatePageLayout();
doc.updateFields();
doc.save(getArtifactsDir() + "Field.INDEX.XE.Formatting.docx");
public void isBold(boolean value)
throws java.lang.Exception
Examples:
Shows how to populate an INDEX field with entries using XE fields, and also modify its appearance.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Create an INDEX field which will display an entry for each XE field found in the document.
// Each entry will display the XE field's Text property value on the left side,
// and the number of the page that contains the XE field on the right.
// If the XE fields have the same value in their "Text" property,
// the INDEX field will group them into one entry.
FieldIndex index = (FieldIndex) builder.insertField(FieldType.FIELD_INDEX, true);
index.setLanguageId("1033");
// Setting this property's value to "A" will group all the entries by their first letter,
// and place that letter in uppercase above each group.
index.setHeading("A");
// Set the table created by the INDEX field to span over 2 columns.
index.setNumberOfColumns("2");
// Set any entries with starting letters outside the "a-c" character range to be omitted.
index.setLetterRange("a-c");
Assert.assertEquals(" INDEX \\z 1033 \\h A \\c 2 \\p a-c", index.getFieldCode());
// These next two XE fields will show up under the "A" heading,
// with their respective text stylings also applied to their page numbers.
builder.insertBreak(BreakType.PAGE_BREAK);
FieldXE indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Apple");
indexEntry.isItalic(true);
Assert.assertEquals(" XE Apple \\i", indexEntry.getFieldCode());
builder.insertBreak(BreakType.PAGE_BREAK);
indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Apricot");
indexEntry.isBold(true);
Assert.assertEquals(" XE Apricot \\b", indexEntry.getFieldCode());
// Both the next two XE fields will be under a "B" and "C" heading in the INDEX fields table of contents.
builder.insertBreak(BreakType.PAGE_BREAK);
indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Banana");
builder.insertBreak(BreakType.PAGE_BREAK);
indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Cherry");
// INDEX fields sort all entries alphabetically, so this entry will show up under "A" with the other two.
builder.insertBreak(BreakType.PAGE_BREAK);
indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Avocado");
// This entry will not appear because it starts with the letter "D",
// which is outside the "a-c" character range that the INDEX field's LetterRange property defines.
builder.insertBreak(BreakType.PAGE_BREAK);
indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Durian");
doc.updatePageLayout();
doc.updateFields();
doc.save(getArtifactsDir() + "Field.INDEX.XE.Formatting.docx");
value - Whether to apply bold formatting to the entry's page number.java.lang.Exceptionpublic java.lang.String getEntryType()
Examples:
Shows how to create an INDEX field, and then use XE fields to populate it with entries.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Create an INDEX field which will display an entry for each XE field found in the document.
// Each entry will display the XE field's Text property value on the left side
// and the page containing the XE field on the right.
// If the XE fields have the same value in their "Text" property,
// the INDEX field will group them into one entry.
FieldIndex index = (FieldIndex) builder.insertField(FieldType.FIELD_INDEX, true);
// Configure the INDEX field only to display XE fields that are within the bounds
// of a bookmark named "MainBookmark", and whose "EntryType" properties have a value of "A".
// For both INDEX and XE fields, the "EntryType" property only uses the first character of its string value.
index.setBookmarkName("MainBookmark");
index.setEntryType("A");
Assert.assertEquals(" INDEX \\b MainBookmark \\f A", index.getFieldCode());
// On a new page, start the bookmark with a name that matches the value
// of the INDEX field's "BookmarkName" property.
builder.insertBreak(BreakType.PAGE_BREAK);
builder.startBookmark("MainBookmark");
// The INDEX field will pick up this entry because it is inside the bookmark,
// and its entry type also matches the INDEX field's entry type.
FieldXE indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Index entry 1");
indexEntry.setEntryType("A");
Assert.assertEquals(" XE \"Index entry 1\" \\f A", indexEntry.getFieldCode());
// Insert an XE field that will not appear in the INDEX because the entry types do not match.
builder.insertBreak(BreakType.PAGE_BREAK);
indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Index entry 2");
indexEntry.setEntryType("B");
// End the bookmark and insert an XE field afterwards.
// It is of the same type as the INDEX field, but will not appear
// since it is outside the bookmark's boundaries.
builder.endBookmark("MainBookmark");
builder.insertBreak(BreakType.PAGE_BREAK);
indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Index entry 3");
indexEntry.setEntryType("A");
doc.updatePageLayout();
doc.updateFields();
doc.save(getArtifactsDir() + "Field.INDEX.XE.Filtering.docx");
public void setEntryType(java.lang.String value)
throws java.lang.Exception
Examples:
Shows how to create an INDEX field, and then use XE fields to populate it with entries.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Create an INDEX field which will display an entry for each XE field found in the document.
// Each entry will display the XE field's Text property value on the left side
// and the page containing the XE field on the right.
// If the XE fields have the same value in their "Text" property,
// the INDEX field will group them into one entry.
FieldIndex index = (FieldIndex) builder.insertField(FieldType.FIELD_INDEX, true);
// Configure the INDEX field only to display XE fields that are within the bounds
// of a bookmark named "MainBookmark", and whose "EntryType" properties have a value of "A".
// For both INDEX and XE fields, the "EntryType" property only uses the first character of its string value.
index.setBookmarkName("MainBookmark");
index.setEntryType("A");
Assert.assertEquals(" INDEX \\b MainBookmark \\f A", index.getFieldCode());
// On a new page, start the bookmark with a name that matches the value
// of the INDEX field's "BookmarkName" property.
builder.insertBreak(BreakType.PAGE_BREAK);
builder.startBookmark("MainBookmark");
// The INDEX field will pick up this entry because it is inside the bookmark,
// and its entry type also matches the INDEX field's entry type.
FieldXE indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Index entry 1");
indexEntry.setEntryType("A");
Assert.assertEquals(" XE \"Index entry 1\" \\f A", indexEntry.getFieldCode());
// Insert an XE field that will not appear in the INDEX because the entry types do not match.
builder.insertBreak(BreakType.PAGE_BREAK);
indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Index entry 2");
indexEntry.setEntryType("B");
// End the bookmark and insert an XE field afterwards.
// It is of the same type as the INDEX field, but will not appear
// since it is outside the bookmark's boundaries.
builder.endBookmark("MainBookmark");
builder.insertBreak(BreakType.PAGE_BREAK);
indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Index entry 3");
indexEntry.setEntryType("A");
doc.updatePageLayout();
doc.updateFields();
doc.save(getArtifactsDir() + "Field.INDEX.XE.Filtering.docx");
value - An index entry type.java.lang.Exceptionpublic boolean isItalic()
Examples:
Shows how to populate an INDEX field with entries using XE fields, and also modify its appearance.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Create an INDEX field which will display an entry for each XE field found in the document.
// Each entry will display the XE field's Text property value on the left side,
// and the number of the page that contains the XE field on the right.
// If the XE fields have the same value in their "Text" property,
// the INDEX field will group them into one entry.
FieldIndex index = (FieldIndex) builder.insertField(FieldType.FIELD_INDEX, true);
index.setLanguageId("1033");
// Setting this property's value to "A" will group all the entries by their first letter,
// and place that letter in uppercase above each group.
index.setHeading("A");
// Set the table created by the INDEX field to span over 2 columns.
index.setNumberOfColumns("2");
// Set any entries with starting letters outside the "a-c" character range to be omitted.
index.setLetterRange("a-c");
Assert.assertEquals(" INDEX \\z 1033 \\h A \\c 2 \\p a-c", index.getFieldCode());
// These next two XE fields will show up under the "A" heading,
// with their respective text stylings also applied to their page numbers.
builder.insertBreak(BreakType.PAGE_BREAK);
FieldXE indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Apple");
indexEntry.isItalic(true);
Assert.assertEquals(" XE Apple \\i", indexEntry.getFieldCode());
builder.insertBreak(BreakType.PAGE_BREAK);
indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Apricot");
indexEntry.isBold(true);
Assert.assertEquals(" XE Apricot \\b", indexEntry.getFieldCode());
// Both the next two XE fields will be under a "B" and "C" heading in the INDEX fields table of contents.
builder.insertBreak(BreakType.PAGE_BREAK);
indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Banana");
builder.insertBreak(BreakType.PAGE_BREAK);
indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Cherry");
// INDEX fields sort all entries alphabetically, so this entry will show up under "A" with the other two.
builder.insertBreak(BreakType.PAGE_BREAK);
indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Avocado");
// This entry will not appear because it starts with the letter "D",
// which is outside the "a-c" character range that the INDEX field's LetterRange property defines.
builder.insertBreak(BreakType.PAGE_BREAK);
indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Durian");
doc.updatePageLayout();
doc.updateFields();
doc.save(getArtifactsDir() + "Field.INDEX.XE.Formatting.docx");
public void isItalic(boolean value)
throws java.lang.Exception
Examples:
Shows how to populate an INDEX field with entries using XE fields, and also modify its appearance.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Create an INDEX field which will display an entry for each XE field found in the document.
// Each entry will display the XE field's Text property value on the left side,
// and the number of the page that contains the XE field on the right.
// If the XE fields have the same value in their "Text" property,
// the INDEX field will group them into one entry.
FieldIndex index = (FieldIndex) builder.insertField(FieldType.FIELD_INDEX, true);
index.setLanguageId("1033");
// Setting this property's value to "A" will group all the entries by their first letter,
// and place that letter in uppercase above each group.
index.setHeading("A");
// Set the table created by the INDEX field to span over 2 columns.
index.setNumberOfColumns("2");
// Set any entries with starting letters outside the "a-c" character range to be omitted.
index.setLetterRange("a-c");
Assert.assertEquals(" INDEX \\z 1033 \\h A \\c 2 \\p a-c", index.getFieldCode());
// These next two XE fields will show up under the "A" heading,
// with their respective text stylings also applied to their page numbers.
builder.insertBreak(BreakType.PAGE_BREAK);
FieldXE indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Apple");
indexEntry.isItalic(true);
Assert.assertEquals(" XE Apple \\i", indexEntry.getFieldCode());
builder.insertBreak(BreakType.PAGE_BREAK);
indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Apricot");
indexEntry.isBold(true);
Assert.assertEquals(" XE Apricot \\b", indexEntry.getFieldCode());
// Both the next two XE fields will be under a "B" and "C" heading in the INDEX fields table of contents.
builder.insertBreak(BreakType.PAGE_BREAK);
indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Banana");
builder.insertBreak(BreakType.PAGE_BREAK);
indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Cherry");
// INDEX fields sort all entries alphabetically, so this entry will show up under "A" with the other two.
builder.insertBreak(BreakType.PAGE_BREAK);
indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Avocado");
// This entry will not appear because it starts with the letter "D",
// which is outside the "a-c" character range that the INDEX field's LetterRange property defines.
builder.insertBreak(BreakType.PAGE_BREAK);
indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Durian");
doc.updatePageLayout();
doc.updateFields();
doc.save(getArtifactsDir() + "Field.INDEX.XE.Formatting.docx");
value - Whether to apply italic formatting to the entry's page number.java.lang.Exceptionpublic java.lang.String getPageRangeBookmarkName()
Examples:
Shows how to specify a bookmark's spanned pages as a page range for an INDEX field entry.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Create an INDEX field which will display an entry for each XE field found in the document.
// Each entry will display the XE field's Text property value on the left side,
// and the number of the page that contains the XE field on the right.
// The INDEX entry will collect all XE fields with matching values in the "Text" property
// into one entry as opposed to making an entry for each XE field.
FieldIndex index = (FieldIndex) builder.insertField(FieldType.FIELD_INDEX, true);
// For INDEX entries that display page ranges, we can specify a separator string
// which will appear between the number of the first page, and the number of the last.
index.setPageNumberSeparator(", on page(s) ");
index.setPageRangeSeparator(" to ");
Assert.assertEquals(" INDEX \\e \", on page(s) \" \\g \" to \"", index.getFieldCode());
builder.insertBreak(BreakType.PAGE_BREAK);
FieldXE indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("My entry");
// If an XE field names a bookmark using the PageRangeBookmarkName property,
// its INDEX entry will show the range of pages that the bookmark spans
// instead of the number of the page that contains the XE field.
indexEntry.setPageRangeBookmarkName("MyBookmark");
Assert.assertEquals(" XE \"My entry\" \\r MyBookmark", indexEntry.getFieldCode());
Assert.assertEquals(indexEntry.getPageRangeBookmarkName(), "MyBookmark");
// Insert a bookmark that starts on page 3 and ends on page 5.
// The INDEX entry for the XE field that references this bookmark will display this page range.
// In our table, the INDEX entry will display "My entry, on page(s) 3 to 5".
builder.insertBreak(BreakType.PAGE_BREAK);
builder.startBookmark("MyBookmark");
builder.write("Start of MyBookmark");
builder.insertBreak(BreakType.PAGE_BREAK);
builder.insertBreak(BreakType.PAGE_BREAK);
builder.write("End of MyBookmark");
builder.endBookmark("MyBookmark");
doc.updatePageLayout();
doc.updateFields();
doc.save(getArtifactsDir() + "Field.INDEX.XE.PageRangeBookmark.docx");
public void setPageRangeBookmarkName(java.lang.String value)
throws java.lang.Exception
Examples:
Shows how to specify a bookmark's spanned pages as a page range for an INDEX field entry.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Create an INDEX field which will display an entry for each XE field found in the document.
// Each entry will display the XE field's Text property value on the left side,
// and the number of the page that contains the XE field on the right.
// The INDEX entry will collect all XE fields with matching values in the "Text" property
// into one entry as opposed to making an entry for each XE field.
FieldIndex index = (FieldIndex) builder.insertField(FieldType.FIELD_INDEX, true);
// For INDEX entries that display page ranges, we can specify a separator string
// which will appear between the number of the first page, and the number of the last.
index.setPageNumberSeparator(", on page(s) ");
index.setPageRangeSeparator(" to ");
Assert.assertEquals(" INDEX \\e \", on page(s) \" \\g \" to \"", index.getFieldCode());
builder.insertBreak(BreakType.PAGE_BREAK);
FieldXE indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("My entry");
// If an XE field names a bookmark using the PageRangeBookmarkName property,
// its INDEX entry will show the range of pages that the bookmark spans
// instead of the number of the page that contains the XE field.
indexEntry.setPageRangeBookmarkName("MyBookmark");
Assert.assertEquals(" XE \"My entry\" \\r MyBookmark", indexEntry.getFieldCode());
Assert.assertEquals(indexEntry.getPageRangeBookmarkName(), "MyBookmark");
// Insert a bookmark that starts on page 3 and ends on page 5.
// The INDEX entry for the XE field that references this bookmark will display this page range.
// In our table, the INDEX entry will display "My entry, on page(s) 3 to 5".
builder.insertBreak(BreakType.PAGE_BREAK);
builder.startBookmark("MyBookmark");
builder.write("Start of MyBookmark");
builder.insertBreak(BreakType.PAGE_BREAK);
builder.insertBreak(BreakType.PAGE_BREAK);
builder.write("End of MyBookmark");
builder.endBookmark("MyBookmark");
doc.updatePageLayout();
doc.updateFields();
doc.save(getArtifactsDir() + "Field.INDEX.XE.PageRangeBookmark.docx");
value - The name of the bookmark that marks a range of pages that is inserted as the entry's page number.java.lang.Exceptionpublic java.lang.String getPageNumberReplacement()
Examples:
Shows how to define cross references in an INDEX field.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Create an INDEX field which will display an entry for each XE field found in the document.
// Each entry will display the XE field's Text property value on the left side,
// and the number of the page that contains the XE field on the right.
// The INDEX entry will collect all XE fields with matching values in the "Text" property
// into one entry as opposed to making an entry for each XE field.
FieldIndex index = (FieldIndex) builder.insertField(FieldType.FIELD_INDEX, true);
// We can configure an XE field to get its INDEX entry to display a string instead of a page number.
// First, for entries that substitute a page number with a string,
// specify a custom separator between the XE field's Text property value and the string.
index.setCrossReferenceSeparator(", see: ");
Assert.assertEquals(" INDEX \\k \", see: \"", index.getFieldCode());
// Insert an XE field, which creates a regular INDEX entry which displays this field's page number,
// and does not invoke the CrossReferenceSeparator value.
// The entry for this XE field will display "Apple, 2".
builder.insertBreak(BreakType.PAGE_BREAK);
FieldXE indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Apple");
Assert.assertEquals(" XE Apple", indexEntry.getFieldCode());
// Insert another XE field on page 3 and set a value for the PageNumberReplacement property.
// This value will show up instead of the number of the page that this field is on,
// and the INDEX field's CrossReferenceSeparator value will appear in front of it.
// The entry for this XE field will display "Banana, see: Tropical fruit".
builder.insertBreak(BreakType.PAGE_BREAK);
indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Banana");
indexEntry.setPageNumberReplacement("Tropical fruit");
Assert.assertEquals(" XE Banana \\t \"Tropical fruit\"", indexEntry.getFieldCode());
doc.updatePageLayout();
doc.updateFields();
doc.save(getArtifactsDir() + "Field.INDEX.XE.CrossReferenceSeparator.docx");
public void setPageNumberReplacement(java.lang.String value)
throws java.lang.Exception
Examples:
Shows how to define cross references in an INDEX field.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Create an INDEX field which will display an entry for each XE field found in the document.
// Each entry will display the XE field's Text property value on the left side,
// and the number of the page that contains the XE field on the right.
// The INDEX entry will collect all XE fields with matching values in the "Text" property
// into one entry as opposed to making an entry for each XE field.
FieldIndex index = (FieldIndex) builder.insertField(FieldType.FIELD_INDEX, true);
// We can configure an XE field to get its INDEX entry to display a string instead of a page number.
// First, for entries that substitute a page number with a string,
// specify a custom separator between the XE field's Text property value and the string.
index.setCrossReferenceSeparator(", see: ");
Assert.assertEquals(" INDEX \\k \", see: \"", index.getFieldCode());
// Insert an XE field, which creates a regular INDEX entry which displays this field's page number,
// and does not invoke the CrossReferenceSeparator value.
// The entry for this XE field will display "Apple, 2".
builder.insertBreak(BreakType.PAGE_BREAK);
FieldXE indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Apple");
Assert.assertEquals(" XE Apple", indexEntry.getFieldCode());
// Insert another XE field on page 3 and set a value for the PageNumberReplacement property.
// This value will show up instead of the number of the page that this field is on,
// and the INDEX field's CrossReferenceSeparator value will appear in front of it.
// The entry for this XE field will display "Banana, see: Tropical fruit".
builder.insertBreak(BreakType.PAGE_BREAK);
indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("Banana");
indexEntry.setPageNumberReplacement("Tropical fruit");
Assert.assertEquals(" XE Banana \\t \"Tropical fruit\"", indexEntry.getFieldCode());
doc.updatePageLayout();
doc.updateFields();
doc.save(getArtifactsDir() + "Field.INDEX.XE.CrossReferenceSeparator.docx");
value - Text used in place of a page number.java.lang.Exceptionpublic java.lang.String getYomi()
Examples:
Shows how to sort INDEX field entries phonetically.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Create an INDEX field which will display an entry for each XE field found in the document.
// Each entry will display the XE field's Text property value on the left side,
// and the number of the page that contains the XE field on the right.
// The INDEX entry will collect all XE fields with matching values in the "Text" property
// into one entry as opposed to making an entry for each XE field.
FieldIndex index = (FieldIndex) builder.insertField(FieldType.FIELD_INDEX, true);
// The INDEX table automatically sorts its entries by the values of their Text properties in alphabetic order.
// Set the INDEX table to sort entries phonetically using Hiragana instead.
index.setUseYomi(sortEntriesUsingYomi);
if (sortEntriesUsingYomi)
Assert.assertEquals(" INDEX \\y", index.getFieldCode());
else
Assert.assertEquals(" INDEX ", index.getFieldCode());
// Insert 4 XE fields, which would show up as entries in the INDEX field's table of contents.
// The "Text" property may contain a word's spelling in Kanji, whose pronunciation may be ambiguous,
// while the "Yomi" version of the word will spell exactly how it is pronounced using Hiragana.
// If we set our INDEX field to use Yomi, it will sort these entries
// by the value of their Yomi properties, instead of their Text values.
builder.insertBreak(BreakType.PAGE_BREAK);
FieldXE indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("愛子");
indexEntry.setYomi("あ");
Assert.assertEquals(" XE 愛子 \\y あ", indexEntry.getFieldCode());
builder.insertBreak(BreakType.PAGE_BREAK);
indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("明美");
indexEntry.setYomi("あ");
builder.insertBreak(BreakType.PAGE_BREAK);
indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("恵美");
indexEntry.setYomi("え");
builder.insertBreak(BreakType.PAGE_BREAK);
indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("愛美");
indexEntry.setYomi("え");
doc.updatePageLayout();
doc.updateFields();
doc.save(getArtifactsDir() + "Field.INDEX.XE.Yomi.docx");
public void setYomi(java.lang.String value)
throws java.lang.Exception
Examples:
Shows how to sort INDEX field entries phonetically.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Create an INDEX field which will display an entry for each XE field found in the document.
// Each entry will display the XE field's Text property value on the left side,
// and the number of the page that contains the XE field on the right.
// The INDEX entry will collect all XE fields with matching values in the "Text" property
// into one entry as opposed to making an entry for each XE field.
FieldIndex index = (FieldIndex) builder.insertField(FieldType.FIELD_INDEX, true);
// The INDEX table automatically sorts its entries by the values of their Text properties in alphabetic order.
// Set the INDEX table to sort entries phonetically using Hiragana instead.
index.setUseYomi(sortEntriesUsingYomi);
if (sortEntriesUsingYomi)
Assert.assertEquals(" INDEX \\y", index.getFieldCode());
else
Assert.assertEquals(" INDEX ", index.getFieldCode());
// Insert 4 XE fields, which would show up as entries in the INDEX field's table of contents.
// The "Text" property may contain a word's spelling in Kanji, whose pronunciation may be ambiguous,
// while the "Yomi" version of the word will spell exactly how it is pronounced using Hiragana.
// If we set our INDEX field to use Yomi, it will sort these entries
// by the value of their Yomi properties, instead of their Text values.
builder.insertBreak(BreakType.PAGE_BREAK);
FieldXE indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("愛子");
indexEntry.setYomi("あ");
Assert.assertEquals(" XE 愛子 \\y あ", indexEntry.getFieldCode());
builder.insertBreak(BreakType.PAGE_BREAK);
indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("明美");
indexEntry.setYomi("あ");
builder.insertBreak(BreakType.PAGE_BREAK);
indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("恵美");
indexEntry.setYomi("え");
builder.insertBreak(BreakType.PAGE_BREAK);
indexEntry = (FieldXE) builder.insertField(FieldType.FIELD_INDEX_ENTRY, true);
indexEntry.setText("愛美");
indexEntry.setYomi("え");
doc.updatePageLayout();
doc.updateFields();
doc.save(getArtifactsDir() + "Field.INDEX.XE.Yomi.docx");
value - The yomi (first phonetic character for sorting indexes) for the index entryjava.lang.Exception