public class FieldSet extends Field
To learn more, visit the Working with Fields documentation article.
Remarks:
Assigns new text to a bookmark.
Examples:
Shows how to create bookmarked text with a SET field, and then display it in the document using a REF field.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Name bookmarked text with a SET field.
// This field refers to the "bookmark" not a bookmark structure that appears within the text, but a named variable.
FieldSet fieldSet = (FieldSet) builder.insertField(FieldType.FIELD_SET, false);
fieldSet.setBookmarkName("MyBookmark");
fieldSet.setBookmarkText("Hello world!");
fieldSet.update();
Assert.assertEquals(" SET MyBookmark \"Hello world!\"", fieldSet.getFieldCode());
// Refer to the bookmark by name in a REF field and display its contents.
FieldRef fieldRef = (FieldRef) builder.insertField(FieldType.FIELD_REF, true);
fieldRef.setBookmarkName("MyBookmark");
fieldRef.update();
Assert.assertEquals(" REF MyBookmark", fieldRef.getFieldCode());
Assert.assertEquals("Hello world!", fieldRef.getResult());
doc.save(getArtifactsDir() + "Field.SET.REF.docx");
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
getBookmarkName()
Gets the name of the bookmark.
|
java.lang.String |
getBookmarkText()
Gets the new text of the bookmark.
|
void |
setBookmarkName(java.lang.String value)
Sets the name of the bookmark.
|
void |
setBookmarkText(java.lang.String value)
Sets the new text of the bookmark.
|
getDisplayResult, getEnd, getFieldCode, getFieldCode, getFormat, getLocaleId, getResult, getSeparator, getStart, getType, isDirty, isDirty, isLocked, isLocked, needStoreOldResultNodes, remove, setLocaleId, setResult, unlink, update, updatepublic java.lang.String getBookmarkName()
Examples:
Shows how to create bookmarked text with a SET field, and then display it in the document using a REF field.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Name bookmarked text with a SET field.
// This field refers to the "bookmark" not a bookmark structure that appears within the text, but a named variable.
FieldSet fieldSet = (FieldSet) builder.insertField(FieldType.FIELD_SET, false);
fieldSet.setBookmarkName("MyBookmark");
fieldSet.setBookmarkText("Hello world!");
fieldSet.update();
Assert.assertEquals(" SET MyBookmark \"Hello world!\"", fieldSet.getFieldCode());
// Refer to the bookmark by name in a REF field and display its contents.
FieldRef fieldRef = (FieldRef) builder.insertField(FieldType.FIELD_REF, true);
fieldRef.setBookmarkName("MyBookmark");
fieldRef.update();
Assert.assertEquals(" REF MyBookmark", fieldRef.getFieldCode());
Assert.assertEquals("Hello world!", fieldRef.getResult());
doc.save(getArtifactsDir() + "Field.SET.REF.docx");
public void setBookmarkName(java.lang.String value)
throws java.lang.Exception
Examples:
Shows how to create bookmarked text with a SET field, and then display it in the document using a REF field.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Name bookmarked text with a SET field.
// This field refers to the "bookmark" not a bookmark structure that appears within the text, but a named variable.
FieldSet fieldSet = (FieldSet) builder.insertField(FieldType.FIELD_SET, false);
fieldSet.setBookmarkName("MyBookmark");
fieldSet.setBookmarkText("Hello world!");
fieldSet.update();
Assert.assertEquals(" SET MyBookmark \"Hello world!\"", fieldSet.getFieldCode());
// Refer to the bookmark by name in a REF field and display its contents.
FieldRef fieldRef = (FieldRef) builder.insertField(FieldType.FIELD_REF, true);
fieldRef.setBookmarkName("MyBookmark");
fieldRef.update();
Assert.assertEquals(" REF MyBookmark", fieldRef.getFieldCode());
Assert.assertEquals("Hello world!", fieldRef.getResult());
doc.save(getArtifactsDir() + "Field.SET.REF.docx");
value - The name of the bookmark.java.lang.Exceptionpublic java.lang.String getBookmarkText()
Examples:
Shows how to create bookmarked text with a SET field, and then display it in the document using a REF field.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Name bookmarked text with a SET field.
// This field refers to the "bookmark" not a bookmark structure that appears within the text, but a named variable.
FieldSet fieldSet = (FieldSet) builder.insertField(FieldType.FIELD_SET, false);
fieldSet.setBookmarkName("MyBookmark");
fieldSet.setBookmarkText("Hello world!");
fieldSet.update();
Assert.assertEquals(" SET MyBookmark \"Hello world!\"", fieldSet.getFieldCode());
// Refer to the bookmark by name in a REF field and display its contents.
FieldRef fieldRef = (FieldRef) builder.insertField(FieldType.FIELD_REF, true);
fieldRef.setBookmarkName("MyBookmark");
fieldRef.update();
Assert.assertEquals(" REF MyBookmark", fieldRef.getFieldCode());
Assert.assertEquals("Hello world!", fieldRef.getResult());
doc.save(getArtifactsDir() + "Field.SET.REF.docx");
public void setBookmarkText(java.lang.String value)
throws java.lang.Exception
Examples:
Shows how to create bookmarked text with a SET field, and then display it in the document using a REF field.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Name bookmarked text with a SET field.
// This field refers to the "bookmark" not a bookmark structure that appears within the text, but a named variable.
FieldSet fieldSet = (FieldSet) builder.insertField(FieldType.FIELD_SET, false);
fieldSet.setBookmarkName("MyBookmark");
fieldSet.setBookmarkText("Hello world!");
fieldSet.update();
Assert.assertEquals(" SET MyBookmark \"Hello world!\"", fieldSet.getFieldCode());
// Refer to the bookmark by name in a REF field and display its contents.
FieldRef fieldRef = (FieldRef) builder.insertField(FieldType.FIELD_REF, true);
fieldRef.setBookmarkName("MyBookmark");
fieldRef.update();
Assert.assertEquals(" REF MyBookmark", fieldRef.getFieldCode());
Assert.assertEquals("Hello world!", fieldRef.getResult());
doc.save(getArtifactsDir() + "Field.SET.REF.docx");
value - The new text of the bookmark.java.lang.Exception